git config --global "John Doe"
git config --global ""
git config --list


Remotes are other git repositories. Typically, we have our main remote git server, and sometimes we also track an upstream git repository.

List remotes:

git remote -v

Add a remote:

git remote add origin

Remove a remote (this has no impact whatsover locally, it can be later re-added):

git remote rm origin

Rename a remote:

git remote rename origin upstream

After adding a remote, fetch changes to be able to see all branches and tags (this does not have any impact locally, unlike a ‘git pull’):

git fetch --all

Diff, log

git show [hash]
git show [tag]

Only for a given file:

git show [hash]  path/to/file

Show revision tree:

git log --all --graph --decorate --oneline


Checkout a specific branch:

git checkout name-of-branch

Create a new branch:

git checkout -b name-of-branch

Push that branch to a remote:

git push origin name-of-branch

From there, we can do a merge-request (Gitlab) or pull-request (Github) to upstream.

Patches (not really useful when using Gitlab/Github)

Check if it applies cleanly:

git apply --check /tmp/foo.patch

Apply the patch:

git apply /tmp/foo.patch

For, attribute a commit to the patch author (replace with correct ‘username’ and numeric user ID):

git commit --author="username <>"

If the patch was created by “format-patch” (contains author information):

git am /tmp/foo.patch

More information: [](Pro Git: Maintaining a Project), page 130


Merge a git repository in a sub-directory

In weird cases where you have your main repository and want to import a sub-repo into your main one:

cd ./other/repo/
mkdir templates
git mv CRM templates/
git commit -m "moving to templates subdir" -a
git filter-branch --index-filter \
'git ls-files -s | sed "s-CRM/-templates/CRM/-" | GIT_INDEX_FILE=$ \
git update-index --index-info &&

Then move back to the root of your main git repository and pull:

cd ../../
git pull

The delete the .git in “other/repo/.git”.