56

I have a Hg repo with 3 branches in it, but two of them are inactive (since I have already merged them into my default branch). hg heads shows 3 heads, one for each branch, even though hg branches shows 2 of those branches as 'inactive'.

When I try to push my default branch (using hg push --branch default http://...) to another repo, the merge is aborted with the message "abort: push creates new remote branches: !"

From the Hg push man pages, "By default, push will not allow creation of new heads at the destination, since multiple heads would make it unclear which head to use. In this situation, it is recommended to pull and merge before pushing."

I've already done that, but I still cant push --branch default without it getting aborted.

Any help is appreciated. Thanks!

simon
  • 3,380
  • 2
  • 22
  • 23

3 Answers3

60

If changesets on default have ancestor changesets on other branchs you have to push those changesets too. It's not possible for a changeset to exist in a repo without all of its changesets also existing.

So try:

hg push --branch default --new-branch

which says "yeah, I know this push sends across a branch name that the remote repo hasn't previously seen before" (it also requires Mercurial 1.6 or later IIRC)>

Also, you can take those inactive heads and make them closed heads with:

hg update thebranch
hg commit --close-branch -m 'closing'

Because "named branches are forever" many folks choose to reserve them for long lived concepts like "stable" and "experimental" and use bookmarks, anonymous branches, or clones for features, releases, and other transitory things. See this for a guide on those other options.

Akhil Jain
  • 13,872
  • 15
  • 57
  • 93
Ry4an Brase
  • 78,112
  • 7
  • 148
  • 169
  • 10
    Your answer is correct, but it doesn't mean I have to like it ;) – simon Feb 02 '11 at 23:08
  • 2
    Fair enough. I avoid named branches entirely. I'm a clones as branches guy. – Ry4an Brase Feb 02 '11 at 23:14
  • 7
    Surely it does. I use git more than I use Merucrial, and I also have a .gitconfig that requires hand editing because git can't update it. Mercurial is unwilling to corrupt your config and git is if you ask it to. They're both valid choices so long as they're documented. I dunno whose article you linked to there, but that guy could use an editor. – Ry4an Brase Oct 19 '12 at 21:04
  • 5
    Here's where the git docs explain that `git config` will cease to work as advertised if you use includes: https://github.com/gitster/git/commit/9b25a0b52e09400719366f0a33d0d0da98bbf7b0 – Ry4an Brase Oct 19 '12 at 21:09
  • 2
    @bambams I wish comments could be downvoted so I could downvote yours. – xyres Feb 24 '16 at 13:35
38

To push a single branch you just use -b

hg push -b myBranch

as for the specific issue, you may want to look into closing branches. I know SourceTree offers it, but I'm not sure on the specifics

Rembrandt Q. Einstein
  • 1,101
  • 10
  • 23
  • 1
    Thanks, this was the answer I was looking for. Simply how to push a single branch. – Sophie McCarrell Feb 05 '14 at 21:22
  • 2
    That's because the branch you are pushing hasn't been pushed to the server yet. If you're pushing an existing branch, this answer works. – dguay Nov 09 '16 at 14:13
0

You can FORCE it!

Here is how:

1. Pull from your repository
2. hg push --rev nnn -f (replace nnn with your Rev # of your working branch)
3. do NOT force before PULLing. if you do things will get out sync and you are screwed

If you are using something like RhodeCode then check it out after forcing it and you will see that your latest branch is there.

However I think that later on Mercurial is going to ask you to push the other branch again, even if you close it, Mercurial will try to create that branch on a server.

I'm a Git user also and ran into the same situation because a customer is using Mercurial but I would like to use Git workflow style.

I think it is doable but I have not figured out 100% yet.

Gilson
  • 1,708
  • 3
  • 16
  • 21