Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git push branch to a new repo with a different name

Tags:

git

branch

How can I push a branch to a different repo with a new name for the branch.

For instance I have a branch feature1 on repo abc and I'd like to push to repo xyz and make it the master branch.

I tried using Renaming remote git branch but then after doing a git clone on the new repo I got the error message

git Warning: remote HEAD refers to nonexistent ref, unable to checkout

Is there a way to specify in the push what I want the destination branch name to be?

like image 305
Daniel Powell Avatar asked Oct 01 '13 00:10

Daniel Powell


People also ask

How do I push a git branch to another repository?

To push the commit from the local repo to your remote repositories, run git push -u remote-name branch-name where remote-name is the nickname the local repo uses for the remote repositories and branch-name is the name of the branch to push to the repository. You only have to use the -u option the first time you push.

How do I push changes from one repo to another?

Show activity on this post. Add a new remote with the url of github-repo into your gitlab-repo then push the changes to github-repo . Go into gitlab repo then add a new remote (say, github-repo ) with the URL of github repo. Push gitlab repo's master branch changes to github repo's master branch.


1 Answers

I think this should work:

git push xyz feature1:master

If master already exists, you can clobber it with -f/--force, or +:

git push -f xyz  feature1:master
git push    xyz +feature1:master

From the man page (in the examples section at the end):

   git push origin +dev:master
       Update the origin repository’s master branch with the dev branch,
       allowing non-fast-forward updates. [...]
like image 146
13ren Avatar answered Sep 23 '22 16:09

13ren