user1941537
user1941537

Reputation: 6695

Does Mercurial push all local branches or only the working branch?

When I have 3 branches like this:

And I'm working on feature/my-branch-1

Once I run

hg push

am I pushing all those 3 branches or only the working branch (feature/my-branch-1)?

Upvotes: 2

Views: 609

Answers (1)

StayOnTarget
StayOnTarget

Reputation: 13048

By default it will push any changesets on all branches which are not already in the destination repository.

You can push only a selected branch by using the -b option:

# hg push --help
hg push [-f] [-r REV]... [-e CMD] [--remotecmd CMD] [DEST]

push changes to the specified destination

    Push changesets from the local repository to the specified destination.
...
options ([+] can be repeated):

..
 -b --branch BRANCH [+]     a specific branch you would like to push
..

Note 1: If you use phases then specifically push will look for any draft or public changes that are not at the destination, and push only those. It will not push any secret changesets. Once they are pushed, draft changesets have their phase changed to public.

(It is possible that you could have unpushed public changesets - for instance if you explicitly marked their phase as public, or perhaps if you transitioned to using phases when you hadn't used them previously.)

Point being, if you want to control which changesets get pushed, phases is a good way to go. You can have everything default to secret and only manually mark things draft when you are ready. This means you can always commit safely without running the risk of pushing something that is not ready.

# hg phase --help                                                               
hg phase [-p|-d|-s] [-f] [-r] [REV...]                                          

set or show the current phase name                                              
...                                                                                
options ([+] can be repeated):                                                  

 -p --public      set changeset phase to public                                 
 -d --draft       set changeset phase to draft                                  
 -s --secret      set changeset phase to secret                                 
 -f --force       allow to move boundary backward                               
 -r --rev REV [+] target revision

Note 2: There are a few cases where push may behave in special ways.

If you have multiple heads on the same branch then generally by default Mercurial will complain and not push anything. (This may not be the exact scenario the OP was asking about, but it is topologically very similar.) In this case each additional head is an "anonymous branch".

By default, push will not allow creation of new heads at the destination, since multiple heads would make it unclear which head to use.

If you really need to, pushing multiple heads can be done "with the -f/--force option, which will push all new heads on all branches" which it advises "will almost always cause confusion for collaborators".

A second case is if the branch you are pushing does not already exist in the destination. Hg will require an extra nudge to push that branch:

Use --new-branch if you want to allow push to create a new named branch that is not present at the destination. This allows you to only create a new branch without forcing other changes.

(text snippets from hg push --help)

Upvotes: 5

Related Questions