Check out a particular branch?
Asked Answered
T

2

18

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

Tar answered 3/12, 2010 at 12:24 Comment(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.Eupheemia
T
9

Ah. I was asking the wrong question.

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

Tar answered 3/12, 2010 at 12:27 Comment(3)
If you have the privileges, you should consider closing this question.Simeon
thanks. I've voted to close it but I don't seem to have the permissions to close it myself.Tar
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 terminologyGeorgiannegeorgic
A
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.

Acerate answered 12/6, 2019 at 15:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.