Git: add a remote repository

In case you need to work with more than one remote repositories, chances are you need to add one of them (origin comes as a default).

$ git remote add remote_name https://github.com/user/repo.git 

Choose the remote_name as you wish and grab the repo URL from github.

You may also be interested in Selecting remote repository on git or maybe if you need to rename your remote, you might want to read how to rename a remote repository

For a little more information, visit: https://help.github.com/articles/adding-a-remote/

Cheers!

Advertisements

Git: Show history of a file

There are two main ways to show the history of a file using git (that is, listing all commits that changed a provided file).

The best one is:

$ git log --follow filename

It will list all commits that ever touched that file, including renames

$ git log -- path/to/file

…will also list all commits, but without resolving file renames.

You might also like git history log of a line, that lists all commits that ever touched a specific line

Reference: https://stackoverflow.com/questions/3701404/list-all-commits-for-a-specific-file

Change the author of a git commit

Issue this command to change the author of the very last commit message:

$ git commit --amend --author="John Doe <john@doe.org>"

To change the author of your config file:

$ git config --global user.name "John Doe"
$ git config --global user.email "john@doe.org"

For more commands, visit https://www.git-tower.com/learn/git/faq/change-author-name-email

For more git quick commands, go to https://quicktechrefs.wordpress.com/?s=git

Cheers!

Change username on linux

To manage every aspect of the user database, you use the usermod tool.

To change username (it is probably best to do this without being logged in):

usermod -l newUsername oldUsername

This, however, does not rename the home folder.

To change home-folder, use

usermod -d /home/newHomeDir -m newUsername

after you changed the username.

Reference: http://askubuntu.com/questions/34074/how-do-i-change-my-username

Create patches with git format-patch

Git has a wonderful tool that allows you to create patches of the commits in the tree of your project: git format-patch.

Usage:

 $ git format-patch [<options>] [<since> | <revision-range>]

More information can be seen via man page:

$ git format-patch -h

or

$ man git format-patch

For example:

$ git format-patch -N

This command generates one .patch file for each of the N commits on the top of your tree. Example:

$ git format-patch -1

Generates a .patch file for the commit on the top of your tree. Increase the number to get one file per commit (for the top 3 commits, use ‘-3’).

To apply the patch, use

$ git am [your-patch].patch

Cheers!

npm/yarn: live-server installation issue

Executive summary:

ISSUE:

$ live-server
zsh: command not found: live-server SOLUTION: $ export PATH=$PATH:/home/user/.yarn/bin/

DETAILS:

Today my attempt to install the live-server package in a Linux Mint Sylvia (Ubuntu Xenial) box using yarn failed. The installation went just fine, with just some info messages:

$ yarn global add live-server
yarn global v1.3.2
[1/4] Resolving packages...
[2/4] Fetching packages...
warning Pattern ["object-assign@latest"] is trying to unpack in the same destination "/home/dbkreling/.cache/yarn/v1/npm-object-assign-4.1.1-2109adc7965887cfc05cbbd442cac8bfbb360863" as pattern ["object-assign@^4.1.0","object-assign@^4"]. This could result in a non deterministic behavior, skipping.
info fsevents@1.1.3: The platform "linux" is incompatible with this module.
info "fsevents@1.1.3" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Installed "live-server@1.2.0" with binaries:
- live-server
Done in 1.98s

Cool! And then..

$ live-server
zsh: command not found: live-server

 

Whatta?

Digging it further I found it (no pun intended) hidden in my home directory:

$ sudo find / -name "*live-server*"
[sudo] password for dbkreling:
find: ‘/run/user/1000/gvfs’: Permission denied
/home/dbkreling/.yarn/bin/live-server
/home/dbkreling/.config/yarn/global/node_modules/.bin/live-server
<...snip...>

Looking at my PATH, I had no .yarn directory whatsoever, so this is what I got:

export_yarn_to_path

After adding ~/.yarn/bin to my $PATH I had no more problems  to run it:

$ export PATH =$PATH:$HOME/.yarn/bin

Cheers!