git Cheat Sheet


  • git remote show origin
    • show info about remote
  • git status
  • git log
    • show commits
  • git diff 93fc6e8
    • show diff of a specific commit

Git Clone

Start to work with a repository

  • git clone [url]

Git Update

  • git fetch
    • Get repository from origin, but do not update files
  • git merge origin/master
    • Merge changes from upstream into your local working space, e.g. when you have no internet connection
  • git pull
    • = git fetch + git merge origin/master (shortcut)

Commit all changes

  • git commit -a -m 'blabla'

Rollback a merge

  • git reset --hard c3e...a7e


  • git stash
    • save local changes which prevent pull
  • git pull
  • git stash pop
    • merge local changes back

Overwrite local repo with all changes from master

WARNING: all local changes are lost!

  • git fetch --all
  • git reset --hard origin/master

A single file:

  • git checkout origin/master myfile.txt

Diff between revisions

  • git diff cbb...705 c3e...a7e

Pull and Rebase

  • git config branch.*branch-name*.rebase true
    • or
  • git config branch.autosetuprebase always


  • Open the Git Repositories view and navigate to the local branch
  • Open the context menu and select Configure Branch...
  • In the resulting dialog, select the Rebase checkbox

Simple git ignore

  • apt install git-extras
  • git ignore myfile.txt

Remote / Origin

  • git remote -v
  • git remote show origin
  • Reconfigure origin:

.gitignore does not work

  • commit changes or you'll loose them with the next command
  • git rm -rf --cached .
  • git add .
  • git commit -m "fixed untracked files"


git rm --cached is used to remove a file from the index. In the case where the file is already in the repo, git rm --cached will remove the file from the index, leaving it in the working directory and a commit will now remove it from the repo as well. Basically, after the commit, you would have unversioned the file and kept a local copy.

git reset HEAD file ( which by default is using the --mixed flag) is different in that in the case where the file is already in the repo, it replaces the index version of the file with the one from repo (HEAD), effectively unstaging the modifications to it.

In the case of unversioned file, it is going to unstage the entire file as the file was not there in the HEAD. In this aspect git reset HEAD file and git rm --cached are same, but they are not same ( as explained in the case of files already in the repo)

Git Config

Show config:

  • git config --list


vi /home/katinga/.gitconfig


Accept Self Signed Certificates


  • git config --global http.sslverify false

Switch branche

  • git checkout branchname

List branches:

  • git branch --all

Checkout a specific revision

  • git checkout d8fj28d

Merge dev into master

I generally like to merge master into the development first so that if there are any conflicts, I can resolve in the development branch itself and my master remains clean.

In the dev branche

  • git pull

  • git merge origin/master -m "merged changes from master"

  • git checkout master (switch to master)

  • git merge --no-ff development (create a separate commit note to find out later, who did the actual merge to master and at which time)

Cherry pick

  • Pick the latest commit from a branche:
    • git cherry-pick myOtherBranche
  • Pick a specific commit from any other branche
    • git cherry-pick 93fc6e8

Create patch files from range of commits

git format-patch 58ce949^..926dc87

git format-patch --stdout 58ce949^..926dc87 > patch1.patch

Apply patches

  • git am *.patch   -> no fuzzy (solution: "-3" option)
  • If that does not work:
    • Revert patch with
      • git am --abort
    • And try
      • git apply -3 xxx.patch
    • Resolve conflicts manually


Move existing, uncommitted work to a new branch


git switch -c myNewBranche

Old / more control:

  • git checkout -b myNewBranche
  • git add ...
  • git commit -m "bla bla"