Mercurial Getting Started#

To work locally with Mercurial repositories, use the following configuration examples and command line instructions.

Configure the .hgrc file#

The ~/.hgrc file is a configuration file which control how Mercurial interacts between the server and your local setup.

For Mercurial usage, you can configure this in your home directory and it will apply to all repositories. Use the following example configuration, and put your own information into the relevant sections.

For more detailed information, and a full rundown of all configuration options, see the Mercurial .hgrc config documentation.

username = username <>
password = password-here

commit = -v

rcdev.prefix =
rcdev.username = username
rcdev.password = set-pw

meld3.executable = /usr/local/bin/meld

git = 1
showfunc = 1
unified = 8

cherry-pick = graft
pull = pull --rebase
push-all = push
push = push --rev .
amend = commit --amend

progress =
mq =
purge =
bookmarks =
hgext.churn =
largefiles =
rebase =
crecord = /Users/brian/crecord/crecord

patterns = re:.*\.(png|bmp|jpg|zip|tar|tar.gz|rar)$
minsize = 10

delay = 1.5

track.current = True

status.modified = green
status.removed = red bold
status.added = cyan bold
status.unknown = white bold
custom.rev = yellow = bold = green
custom.branch = red bold underline = underline
changeset.draft = yellow
changeset.public = green

pager = LESS='FSRX' less

Configure the .hgignore file#

The ~path/to/repo/.hgignore file is a configuration file that instructs Mercurial to ignore certain files and not commit them to the repository. Files such as build files, or editor tracking files are usually not committed to a repository.

Create the .hgignore file in your repository, and configure it using the following example to ignore the files you do not wish to be added to version control. For more information, see the hgignore documentation

syntax: glob

Using basic Mercurial commands#

The following commands will get you through the basics of using Mercurial on the command line. For a full run through of all Mercurial commands and options, see the Mercurial Command Line Reference Guide

  • hg init - Create a Mercurial repository.

  • hg clone URI - Clone a repository to your local machine.

  • hg status - Display the status of a repository.

  • hg commit -m “xx” - Commit changes with an ‘xx’ commit message.

  • hg pull - Pull changes on server into the local repository.

  • hg push - Push your local changes to the server.

  • hg outgoing - Display commits in your next push.

  • hg incoming - Display commits being pulled locally on the next pull.

  • hg heads - Display repository versions, when multiple heads get created you need to merge them.

  • hg update -r REV - Revert to specified revision.

  • hg update -C - Disregards any uncommited changes.

  • hg merge -r tip - Merge changes with tip.

  • hg log - Show the repository history.

  • hg rollback - Rollback certain revisions.

  • hg diff - Show file diffs on your terminal.