Git Cheat Sheet
Create a Repository Working With Branches Make a Change Synchronize
From scratch -- Create a new local repository List all local branches Stages the file, ready for commit Get the latest changes from origin (no merge)
$ git init [project name] $ git branch $ git add [file] $ git fetch
Download from an existing repository List all branches, local and remote Stage all changed files, ready for commit Fetch the latest changes from origin and merge
$ git clone my_url $ git branch -av $ git add . $ git pull
Switch to a branch, my_branch, and update Commit all staged files to versioned history Fetch the latest changes from origin and rebase
Observe a Repository working directory $ git commit -m “commit message” $ git pull --rebase
List new or modified files not yet committed $ git checkout my_branch
$ git status Commit all your tracked files to versioned Push local changes to the origin
Create a new branch called new_branch history $ git push
Show the changes to files not yet staged $ git branch new_branch $ git commit -am “commit message”
$ git diff
Delete the branch called my_branch Unstages file, keeping the file changes
Show the changes to staged files $ git branch -d my_branch $ git reset [file] Finally!
$ git diff --cached When in doubt, use git help
Merge branch_a into branch_b Revert everything to the last commit
$ git [command] –help
Show all staged and unstaged file changes $ git checkout branch_b $ git reset --hard
$ git diff HEAD $ git merge branch_a
Or visit training.github.com for official GitHub
Show the changes between two commit ids Tag the current commit training.
$ git diff commit1 commit2 $ git tag my_tag
List the change dates and authors for a file
$ git blame [file]
Show the file changes for a commit id and/or file
$ git show [commit]:[file]
Show full change history
$ git log
Show change history for file/directory including
diffs
$ git log -p [file/directory]
www.jrebel.com