11

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?

Community
  • 1
  • 1
Daniel Powell
  • 8,143
  • 11
  • 61
  • 108

1 Answers1

22

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. [...]
13ren
  • 11,887
  • 9
  • 47
  • 64
  • 2
    That works great, although if the branch doesnt exist it requires using /refs/heads/master eg. git push xyz feature1:refs/heads/master – Daniel Powell Oct 01 '13 at 01:05