Appendix

Git Cheat Sheet

Action

Command

Create new repository

$ git init

Create shared repository

$ git init –-bare –-shared=all

Clone repository

$ git clone c:/demo1 c:/demo2

Checkout branch

$ git checkout <name>

Create branch

$ git branch <name>

Delete branch

$ git branch -d <name>

Merge branch (from the branch to merge into):

$ git merge PDC

Solve conflicts (add –tool=kdiff3 if no mergetool is specified)

$ git mergetool $ git commit

Create tag

$ git tag <name>

Add files/changes (. for all files)

$ git add .

Commit added files/changes (–amend to amend to last commit)

$ git commit –m “Enter commit message”

Discard changes

$ git reset –hard

Create patch (-M = detect renames –C = detect copies)

$ git format-patch –M –C origin

Apply patch without merging

$ git apply c:/patch/01-emp.patch

Merge patch

$ git am -–3way –-signoff c:/patch/01-emp.patch

Solve conflicts (add –tool=kdiff3 if no mergetool is specified)

$ git mergetool
$ git am –-3way -–resolved

Stash changes

$ git stash

Apply stashed changes

$ git stash apply

Pull changes (add –rebase to rebase instead of merge)

$ git pull c:/demo1 master

Solve conflicts (add –tool=kdiff3 if no mergetool is specified)

$ git mergetool
$ git commit

Push changes (in branch $ git push c:/demo1 master master:<new>)

$ git push c:/demo1

Blame

$ git blame –M –w <filename>

Help

$ git <command> –help

Here are some default names used by Git.

Default names

master

default branch

origin

default upstream repository

HEAD

current branch

HEAD^

parent of HEAD

HEAD~4

the great-great grandparent of HEAD