Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hg: how do I push newly created branch back into central repository?

I cloned the centeral repository via

hg clone my_project my_project_1 

then after switching to a newly created repo I marked as a new branch

hg branch v1 

While inside the new clone I issued

hg ci -m "branch created" 

but when I tried to push the changes back to the original repository I cloned from I got this error:

abort: push creates new remote branches: v1! 

How do I push the branch into the original repository? Am I doing the right thing by trying to push the branch into the original repo? I just want to have a centralized repository which would contain branches and from which I would be able to check out branches. What's the best way to deal with this problem? Thank you.

like image 687
Alex Khvatov Avatar asked Aug 02 '10 19:08

Alex Khvatov


People also ask

How do I push a new branch?

Push a new Git branch to a remote repo Clone the remote Git repo locally. Create a new branch with the branch, switch or checkout commands. Perform a git push with the –set-upstream option to set the remote repo for the new branch. Continue to perform Git commits locally on the new branch.

How do I push changes to a remote branch?

In some cases, you may want to push your changes to another branch on the remote repository. In order to push your branch to another remote branch, use the “git push” command and specify the remote name, the name of your local branch as the name of the remote branch.


1 Answers

It depends on the version of Mercurial that you're using. The command used to be hg push -f ... or hg push --force ... to force the creation of a new branch in the remote repository (which is usually OK).

However, using -f also allows you to create new heads in the remote repository (usually not OK), so current versions of Mercurial (1.6 and above) have a --new-branch option to hg push that allows you to create a branch, but not create a new head, so the command is:

hg push --new-branch 

You can also limit pushes to just the branch that you're working on with the -b flag, so:

hg push --new-branch -b v1 
like image 70
Niall C. Avatar answered Oct 11 '22 18:10

Niall C.