Chris Colborne

Git and Mercurial Cheat Sheet

February 01, 2015

Illustration from unDraw

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 initgit init

Add Remote

edit paths in .hg/hgrc git remote add origin [email protected]:<username>/<repo-name>.git


hg clone <url>git clone <url>


hg pull -ugit pull


hg pushgit push


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

See incoming/outgoing commits

hg ingit fetch && git log master..FETCH_HEAD
hg outgit fetch && git log FETCH_HEAD..master


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

Interactively commit part of working copy

hg recordgit add --patch && git commit


hg branch <branch-name>git checkout -b <branch-name>
hg up <branch-name>git checkout <branch-name>
hg push --new-branchgit push origin <branch-name> -u
hg branchesgit 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 shelvegit stash
hg unshelvegit stash pop

Clear working copy

hg up -Cgit checkout -f


hg rollbackgit 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

Like what you've read?

Why not subscribe to my mailing list to get my latest articles by email.

I respect the privacy of your email address. You can unsubscribe at any time.

Written by Chris Colborne, an Aussie software engineer from Brisbane, Australia. Follow me on Twitter

Chris Colborne © 2023