Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is a --new-branch flag needed?

Tags:

mercurial

Isn't this a normal workflow?

[default] $ hg branch foo

[foo] $ [... some commits ...]

[foo] $ hg update default

[default] $ hg merge foo

[default] $ hg commit -m "merged foo"

[default] $ hg push
abort: push creates new remote branches: foo!
(use 'hg push --new-branch' to create new remote branches)

What is the otherwise ideal way to do branching → merging → pushing?

like image 957
Vaibhav Bajpai Avatar asked Aug 04 '11 21:08

Vaibhav Bajpai


People also ask

Why create new branch Git?

In Git, branches are a part of your everyday development process. Git branches are effectively a pointer to a snapshot of your changes. When you want to add a new feature or fix a bug—no matter how big or how small—you spawn a new branch to encapsulate your changes.

Do you have to push a branch?

Normally, you will push to a branch and add to its commit history. But, there are times when you need to forcefully overwrite the history of a branch. There are a couple reasons you may want to do this. The first reason is to fix a mistake—although it is probably better to just make a new commit reverting the changes.

How to create a new branch in Git repository?

The git branch command can be used to create a new branch. When you want to start a new feature, you create a new branch off main using git branch new_branch . Once created you can then use git checkout new_branch to switch to that branch.


2 Answers

The mercurial philosophy is that you should not be pushing things which make it harder for other users of the repository. Relevant to this question is that multiple heads make it harder for other developers, since they would then need to merge your changes. Hence by default pushing new heads is rejected by the server. The -f option was used to allow pushing new heads.

However, the case of pushing a new named branch is quite different conceptually to pushing a new head on the same branch. Many workflows (including mine) do each task on a separate named branch. The --new-branch option allows you to push up a new branch, whilst rejecting new heads on existing branches. It's also different (as you've seen) because it's needed even if the new branch does not create a new head (due to merging).

My personal feeling is that new branches should be allowed by default, but the mercurial developers prefer otherwise.

like image 149
Tim Delaney Avatar answered Oct 22 '22 14:10

Tim Delaney


This is a one-time thing. Just use --new-branch the first time you push a (new) branch. It's normal.

Every other push can remain as hg push, no --new-branch flag.

like image 31
Matt Ball Avatar answered Oct 22 '22 14:10

Matt Ball