Git Cheat Sheet

The following is a reference of Git commands that I’m using every now and then. For a complete guide take a look at the online documentation.

Suppress tracking

A text file named .gitignore suppresses accidental versioning of files and paths matching the specified patterns. GitHub can help you set up your .gitignore files.

git ls-files –other –ignored –exclude-standard

Lists all ignored files in this project.

Mirror changes

git remote set-url origin --push --add
git remote set-url origin --push --add

Adds two new remote repositories as targets for git push. Every call of git push will push changes into both specified repositories.

Bisect changes

git bisect start --term-good=unfixed --term-bad=fixed [1]

Use fixed and unfixed instead of good and bad

Using host aliases

You can configure host aliases by updating your ~/.gitconfig like this:

[url "git@github"]
    insteadOf = github

Instead of cloning from, you can use github:ORGANIZATION/PROJECT.git. Specify which key is used by updating your ~/.ssh/config like this:

Host github
  User git
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/key-for-github

Git will resolve github into git@github and your SSH client will resolve github as and use the specified key. The same approach can be used to configure different keys on a per project or organization basis.