18

How do I check out a particular named branch of a Mercurial repo?

Mark Amery
  • 143,130
  • 81
  • 406
  • 459
AP257
  • 89,519
  • 86
  • 202
  • 261
  • Duplicate of [How do I "switch" with Mercurial](http://stackoverflow.com/questions/1156152/how-do-i-switch-with-mercurial), and this question's author wanted to close it as a dupe (see the comments on the answer), but this was before question authors had the power of unilateral duplicate closure. Passers by with close vote privilege: please VTC. – Mark Amery Apr 30 '16 at 12:48

2 Answers2

9

Ah. I was asking the wrong question.

I needed to know how to switch to a particular branch in Mercurial.

Community
  • 1
  • 1
AP257
  • 89,519
  • 86
  • 202
  • 261
  • 1
    If you have the privileges, you should consider closing this question. – Oben Sonne Dec 03 '10 at 12:46
  • thanks. I've voted to close it but I don't seem to have the permissions to close it myself. – AP257 Dec 07 '10 at 17:00
  • 9
    I think this question and answer are excellent and shouldn't be closed. As a newcomer to DVCS, I'd also have asked the same question without knowing the correct terminology – Johann Gerell May 18 '11 at 07:52
2

The terminology you've used here is check out.

If you're coming from git, then this means you probably want to set the state of your working directory to whatever is in the particular named branch.

In SVN, you might call this switching. While the answer to this question may be the same, if you ask the same question using git terminology (as you did here), you might not find that answer, so this question is still useful in itself.

In Mercurial, it's called updating: You update the contents of your working tree, like so:

hg update -c <your-named-branch>

The -c isn't necessary, but if you're used to git warning you before anything is permanently overwritten, you'll find it more comfortable. Use -C instead to wipe all local changes, or -m to merge changes.

If you're trying to check out a branch that only exists on a remote repository, you might want to use this instead:

hg pull -u <your-named-branch>

Or else just pull (without -u) first so that the remote branch is brought into your local repository before you use update.

If you prefer git parlance, you'll be pleased to know that checkout and co are both aliases for update. You can also use -r to specify a revision. See the update help page for more detail.

M_M
  • 1,955
  • 2
  • 17
  • 23