A GIT cheat sheet

Clone (download all code and create a local repository)

 git clone ssh://user@domain.com/repo.git
Note: you do this only once after that you use "git pull" to keep up with the latest changes from others.

Update local repository with latest changes

 git pull

Push your changes to the git server

 git status  # see what you have changed
 git pull    # get the latest code from the server, will not overwrite your changes
 git add all_the_files_you_want_to_push
 git commit -m "summary of what you did"
 git push
Note: you can use "git add -u" to add everything that is listed in "git status" in the upper section as modified or deleted. In other words "git add -u" adds all changes to tracked files.

If you did accidently add too many files with "git add" and you notice the problem before you typed "git commit" then you can type "git reset" and start over with "git add".

Undo changes in one file

git checkout filename

Look at the change history

git log 
# see change details:
git log -u
# nice branch display:
git log --all --graph --decorate --oneline --simplify-by-decoration

Show diff to previous version

git diff the/file.txt

Review history of changes for a given file

git log -u the/file.txt
Show the difference between two versions:
#fist find the commitIDs:
git log the/file.txt
git diff -u commitID1:./the/file.txt commitID2:./the/file.txt
Who changed what and when in the file:
git blame the/file.txt

Show previous version of a file

# show previous version of the/file.txt on master branch:
git show master~1:the/file.txt
Go back in time by checking out an older commit:
git log
git checkout commitId

Checkout a branch other than master

# see if there are any changes that could cause problems:
git status 
# list the branches:
git branch -va
git checkout branchname

List files ignored by .gitignore

git ls-files --others -i --exclude-standard

Merge a single commit from any other branch into this repro

git cherry-pick commitId

Show branches

git branch -va

Git config

# list config:
git config -l
Some reasonable configuration settings (do this once per local machine):
git config --global user.email your@email
git config --global user.name yourUserId
git config --global branch.autosetupmerge always
git config --global color.ui true
git config --global core.excludesfile .gitignore
git config --global push.default tracking

Links to other GIT cheat sheets




Written by Guido Socher