Git: Cheat Sheet

July 2nd, 2009 by jeremychone

Create and Swith branch

git checkout -b my_new_branch

List local and remote branches

git branch -a

Git reset -hard (good to undo merge)

git reset --hard

abandon everything since your last commit; this command can be DANGEROUS. If
merging has resulted in conflicts and you’d like to just forget about the
merge, this command will do that.

Git reset –hard HEAD^ (remove completely last commit)
git reset --hard HEAD^

Git revert last commit (this will add another commit to remove the old one)

git revert HEAD

Git clean (remove untrack files) source

git clean -f

clean directory as well:

git clean -fd

If you just want to remove ignored files, run “git clean -f -X”. If you want to remove ignored as well as non-ignored files, run “git clean -f -x”

Git Abort when git am breaks

git am --abort

Git Tag (see Git tag cheat sheet)

Tag a specific branch

git tag stable-1 1b2e1d63ff

Viewing available tags is done with -l:

git tag -l

Annotated tag:

git tag -a -m "Tagging release 1.0" v1.0

Viewing tags with annotation:

git tag -l -n1

Delete a tag:

git tag -d tag_name

Push tags:

git push origin --tags

Checkout tag

git checkout -f -b [new branch name] [tag]/[sha1]

See also

Leave a Reply