The Fetch Extension

posted by Zachary Voase on September 29, 2009

Users who have recently migrated from Git are often surprised by the behaviour of hg pull. Whereas git pull updates the working directory, automatically merges and commits, hg pull just adds the remote changesets to your local repo without touching your working directory.

9 times out of 10, you’ll want the auto-merge style. Fortunately, it’s not far away. Edit your ~/.hgrc file and add this:

[extensions]
hgext.fetch =

Now, you can go from this:

$ hg pull
$ hg update remote_head
$ hg merge local_head
$ hg commit -m "Merged."

To this:

$ hg fetch

By default, fetch will use the head of the pulled remote changes as the first parent of the merge, and the head of your local changes as the second parent. You can make it perform the opposite by using:

$ hg fetch --switch-parent

For more information, consult the wiki documentation and the the output of hg help fetch.

If you’ve migrated from Git and miss the auto-merging action of git pull, this might be the extension you’re looking for.