How do I “switch” with Mercurial

How do I do what svn switch does, in Mercurial?

That is change my working directory to switch to another branch in the repository?

  • How do I specify a merge-base to use in a 'hg merge'
  • Which Distributed Source Control System has the best integration with Windows & Visual Studio?
  • How to deal with Git submodules on a repo that is converted to Mercurial
  • Mercurial Subrepositories: Prevent accidental recursive commits and pushes
  • Mercurial: Named Branches vs Multiple Repositories
  • Advantages of GitHub over Bitbucket for Git Repositories
  • Update git-svn list of remote branches
  • Using SharpSvn to retrieve log entries within a date range
  • For a .Net project, what file extensions should I exclude from source control?
  • How to maintain “Ignore/handle subsequent exceptions” breakpoints between developers?
  • svn: Symbolic links are not supported on this platform - Windows 8.1
  • Any way to guarantee that a git user doesn't use fake account info when commiting and pushing?
  • 5 Solutions collect form web for “How do I “switch” with Mercurial”

    hg update -r<REV>
    

    The update command will switch to a specified revision.

    The switch command does two things in Subversion:

    1. Update the working copy to mirror a new URL within the repository.
      This behaviour is similar to ‘svn update‘, and is the way to
      move a working copy to a branch or tag within the same repository.

    2. Rewrite working copy URL metadata to reflect a syntactic change only.
      This is used when repository’s root URL changes (such as a scheme
      or hostname change) but your working copy still reflects the same
      directory within the same repository.

    The hg update foo command matches the former most closely if you switch from, say, /trunk to /branches/foo in Subversion.

    If you want to do the latter, then simply edit .hg/hgrc. You’ll find a [paths] section that looks like this:

    [paths]
    default = http://example.net/something
    

    and you can change this default push/pull URL to something else as you see fit. You can also add other entries to this section if you often need to push/pull from other locations. If you want to pull from one location, but push to another, then add a default-push entry.

    I you want to switch branches, do the following:

    First check what branches are available, type hg branches. This will list all the available branches.

    Next determine which branch you are currently working on, type hg branch. This will tell you what is your current branch.

    Finally to switch a branch (and wipe all local changes), type hg update -C name-of-branch. This will switch you to the branch name you specified.

    Verify by typing hg branch again.

    To switch to a remote branch ‘tip’:

    hg pull -u <remote_branch>
    

    For local branch (already up-to-date) just:

    hg update -r <local_branch>
    

    Alternate answer, in case by “branch” you mean “another clone of the repo that lives in some arbitrary location on the net”: you can’t.

    In other words, given a repo at hg.a.com, and a clone of that repo hg.b.com, there is no command like

    hg switch hg.b.com .
    

    (using svn parlance there, assuming your current directory is the root of a clone of hg.a.com).

    However, you can clone hg.a.com, locally clone that clone (which should be relatively inexpensive), and then pull from hg.b.com to pick up any additional changes that might live there.

    Git Baby is a git and github fan, let's start git clone.