Search code examples
gitversion-controlmercurial

How to retrieve to which remote and remote branch the current branch is corresponding to in Mercurial?


To get the corresponding to the current branch name of remote and name of remote branch in Git the following command can be used:

git rev-parse --abbrev-ref --symbolic-full-name @{u}

It returns something like:

<some-remote-name>/<some-remote-branch-name>

Where <some-remote-name> is the name of the remote and <some-remote-branch-name> is the name of the remote branch which the current branch tracks.

For example, it can be:

origin/master

How to do the same thing in Mercurial?


Solution

  • Mercurial branches do not have Git semantics; a branch name in Mercurial is not a head and these concepts just don't really correspond. Branch names in Mercurial are truly global and the name you use in your repository is the name that other Mercurial repositories will use in their repositories.1 Branch names in Git have an upstream setting, but branch names in Mercurial do not (they have no need for this concept). The branch that a commit is made on, is the branch the commit will forever be on; it will never be on any other branch.


    1The Convert extension allows the names to map back and forth to different strings across different Mercurial repositories, but the fundamental issues remain, here.