Git and Mercurial Cheat Sheet

Our team supports a large number of applications, ranging from legacy apps in SVN, to more recent apps in Mercurial, to our latest projects in Git.

Inspired by the excellent (but very thorough) Mercurial to Git Rosetta stone, here is a bare bones, back to basics, KISS mapping between Hg and Git of the most common operations I use on a day to day basis.


hg init git init

Add Remote

edit paths in .hg/hgrc git remote add origin<username>/<repo-name>.git


hg clone <url> git clone <url>


hg pull -u git pull


hg push git push


hg diff git diff
git diff HEAD (to diff both staged and unstaged)
hg diff -r 20:21 ./src/filename git diff <hash>..<hash> -- ./src/filename
... coming ... git diff master...<hash> (to diff RHS with common ancestor)

See incoming/outgoing commits

hg in git fetch && git log master..FETCH_HEAD
hg out git fetch && git log FETCH_HEAD..master


hg ci -m"Commit message" git commit -am"Commit message"

Interactively commit part of working copy

hg record git add --patch && git commit


hg branch <branch-name> git checkout -b <branch-name>
hg up <branch-name> git checkout <branch-name>
hg push --new-branch git push origin <branch-name> -u
hg branches git branch -a
hg commit --close-branch # delete local branch
git branch -d <branch-name>
# delete remote branch (NB the colon)
git push origin :<branch-name>
# remove remote tracking branches that no longer exist
git fetch -p
# show commits from branch
hg log -b <branch-name>
git reflog show <branch-name>


hg merge <branch-name or commit number/hash> git merge <branch-name or commit hash>


hg shelve git stash
hg unshelve git stash pop

Clear working copy

hg up -C git checkout -f


hg rollback git reset HEAD~

Remove ignored files that are already committed

hg forget "set:hgignore() and not ignored()" git ls-files --ignored --exclude-standard | xargs git rm --cached
comments powered by Disqus