4

I checked out a branch let's call 1.14 from the remote 1.14 branch. I made local changes and made a commit, changed my local branch to something else, let's call mynew. If I run git branch -vv I see that

mynew efe918d [origin/1.14: ahead 1] commit_msg

Now I want to push this mynew not into the origin/1.14 but a new let's call origin/mynew, which isn't exist yet, I want to create it by pushing the local one.

How could I do this?

4 Answers 4

6

You can specify the destination branch on push command

git push origin localBranch:remoteBranch

In your case you can write

git push origin mynew:mynew

If mynewdoesn't exist on the server, it will create it.

To set up mynew local branch to be linked (when pulling, pushing) to remote mynew branch use -u or --set-upstream equivalent option

git push -u origin mynew:mynew
2

If you are on mynew 's branch, git push -u origin mynew will push on a new branch called mynew.

1
  • There are some cases and settings where this will work, and some where mynew:mynew is required. It's always safe to be explicit (mynew:mynew) so Flows' answer is better here.
    – torek
    Commented Feb 23, 2017 at 17:06
1

Just Push your local mynew branch. A new origin/mynew will be created and track automatically.

$ git checkout mynew
$ git push -u origin mynew
0

This pushes the mynew branch to origin and sets its upstream to the new created origin/mynew.

git push origin mynew --set-upstream

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.