James Wierzba James Wierzba - 2 months ago 13
Git Question

How to create new branch in a remote?

I have made a mistake with my git branch workflow

I have the following local and remote branches setup:

master -> origin/master
iteration5 -> origin/iteration5
iteration9 -> origin/iteration5


I need the upstream on my local branch (
iteration9
) to be set to a remote branch called
origin/iteration9
.

Given the current state of my repo, how can I create a remote branch called
iteration9
based off of my local branch
iteration9
, if it is already pointing to an old remote branch (
origin/iteration5
)

Answer

You can remove it with

git branch --unset-upstream iteration9

then reset it by pushing to origin with the --set-upstream flag:

git push --set-upstream origin iteration9

or you can set it with this command if the remote branch already exists:

git branch --set-upstream-to=origin/iteration9
Comments