18

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

1
  • Duplicate of 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. Commented Apr 30, 2016 at 12:48

2 Answers 2

9

Ah. I was asking the wrong question.

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

Sign up to request clarification or add additional context in comments.

3 Comments

If you have the privileges, you should consider closing this question.
thanks. I've voted to close it but I don't seem to have the permissions to close it myself.
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
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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.