Make another branch default?

11,783

Solution 1

Just merge feature-branch into default then close feature-branch:

$ hg checkout default
$ hg merge feature-branch
$ hg commit
$ hg checkout feature-branch
$ hg commit --close-branch

There is no more clean and sensible way (that I'm aware of) to “make feature-branch the default”.

One thing that wouldn't be as nice, but you could do, is to make a commit to default on top of feature-branch:

$ hg checkout feature-branch
$ hg branch default
$ hg commit

But this would leave two heads in the default branch, which is suboptimal.

Solution 2

Since Mercurial 2.4, you can create an bookmark called @ and Mercurial will checkout that revision new clones.

However, I would still try to stick with using default as the branch where the main development takes place. Doing so will cause the least amount of surprise for developers already used to Mercurial — the wiki describes the standard way to use branches in Mercurial.

If you follow the conventional advice of using default as the main branch for development, then you should close your feature branch before you merge it back:

$ hg update feature-branch
$ hg commit --close-branch -m "Feature done, merging into default branch"
$ hg update default
$ hg merge feature-branch
$ hg commit

If you haven't done any work at all on the default branch since your started the feature branch, then this merge will be trivial and have no conflicts. Otherwise you'll have to resolve conflicts. If you're sure you want to keep everything from the feature branch, then you can do

$ hg merge --noninteractive --tool internal:local feature-branch
$ hg revert --all --rev feature-branch

instead of just hg merge above. That will make sure that the new commit on default look exactly like the last commit on feature-branch.

Solution 3

I succeded without merging by closing the default branch.

in my development repository working directory:

$ hg update default

$ hg commit --close

then my development branch became the new default branch. But i do not know the rules for why my development branch was choosen as the new default. i think it is because it was my tip ? (or maybe last changed branch? (tip?))

I also think that you have to repeat that next time. Because i think my chosen branch name was "overwritten" by the 'default' name.

It would be nice to have branch name.

dev-projectname-version.x=default

regards

Solution 4

I wanted to do just what you described and hunted around until I found an answer which uses the revert command to do just what you describe. Here is the code I used:

hg revert --all --rev ${1}

hg commit -m "Restoring branch ${1} as default"

where ${1} is the number of the revision or the name of the branch. These two lines are actually part of a bash script, but they work fine on their own if you want to do it manually.

This is useful if you need to add a hot fix to a release branch, but need to build from default (until we get our CI tools right and able to build from branches and later do away with release branches as well).

Share:
11,783
dartdog
Author by

dartdog

Open Software professional Developing Open SoftWare Co, oswco

Updated on July 06, 2022

Comments

  • dartdog
    dartdog almost 2 years

    I have a Mercurial repo at Bitbucket and on my local machine, both are mirrors, up to date. I created a feature branch, reflected in both repos. I did all my work in the feature branch.

    The feature branch is now complete and I want to now make it the default for the main repo and my local copy. I don't really care about the default branch, enough work has gone into the feature branch that all I want to do is designate it as the new default.

    I don't think I want to merge nor should I? How can I do this so both local and remote don't get confused?