home
Git cheat sheet
Improve your Git skills
print

git version: 2.9+ - Date: March 2017

Local Git State and changes

gitZone

Manage local changes

Show changes between commits, commit and working tree gitDiff

Show the working tree status git status

Add contents to the index git add <file>

Add current contents of the index in a new commit git commit -m 'subject' -m 'body'

Who changed what in git blame <file>

Remote

List all remotes repositories git remote -v

Show information about remote git remote show <remote>

Add new remote repository git remote add <remote> <url>

Dowload all changes from git fetch <remote>

Download changes and integrate into HEAD git pull <remote> <branch>

Publish changes on a remote git push <remote> <branch>

Branch

Create a new local branch and switch HEAD branch git checkout -b newBranch

Delete a local branch git branch -d <branch>

Commit messages

  • Limit the subject line to 50 characters
  • Do not end the subject with a period
  • Use the imperative mood in the subject line
  • Use the body to explain what, why and how

Tips: Separate subject from body with a blank line. From de command line you can use: git commit -m 'subject' -m 'body'


Tag

Tag a commit git tag <tag-name>

Merge

Merge on your current branch git merge <branch>

Reapply commits (of the ) on top of you current branch git rebase <branch>

Undo

List all operations on repository git reflog

Discard all local changes in your working directory git reset --hard HEAD

Discard local changes in a file git checkout HEAD <file>

Revert a commit (add a new commit with contrary changes) git revert <commit>

Change the last commit git commit --amend Be careful: don't amend a published commit!

Settings

Some commands to change the default git behavior git config --global pull. rebase true git config --global rerere.enabled 1

Proxy

Add proxy on your global configuration git config --global http.proxy http://proxy.com:1234

Unset the global proxy git config --global --unset http.proxy

Add proxy on your current project directory git config http.proxy http://proxy.com:1234

Check your global proxy git config --global --get http.proxy

Check your local proxy git config --get http.proxy

Commit rules

  • One commit for one task: if you have 2 tasks written in one file you can use git add -p and chose which chunk you need to add at your commit
  • Try to commit as often as possible
  • Do not commit a half-done work. You should only commit code when it's completed.
  • Commit a stable version of your work: the tests should not failed

default client

Visualize git tree gitk --all

Graphical git operations git gui