Wednesday, January 25, 2012

Git Reference card

Git create remote branch

To create a local branch

git branch branch_name

To switch/checkout local branch

git checkout branch_name

You can combine above two in one step instead

git checkout -b your_branch

Create remote branch (so that other co-workers/programmers/whoever can pull)

git push -u origin your_branch

Others can pull this by

git checkout origin/your_branch

View diff in GIT

What you will commit

git diff

diff between two branch

git diff master..branch_1

diff since last commit

git diff HEAD

Diff with stash

git stash show -p stash@{0}

Git create and apply patch

git diff --no-prefix > patchfile


patch -p0 < patchfile

Detail on stackoverflow

Ignore files

Easiest way is to create a .gitignore file in root folder. You can have .gitignore in subfolders in case you want to include rules specific to subfolders. This does not apply to already tracked file. To ignore already tracked file you would need to remove it from Git. In case you want to retain the file

git rm --cached

Undo last commit

git reset --soft HEAD^

Read more about this on Stackoverflow

This entry is a note to self for being amnesiac


Post a Comment