"Renaming" a remote branch is actually a 2 step process (not necessarily ordered):
git push [space]:<old_name>
as ksrb explained);I use TortoiseGit and when I first tried to delete the branch through the command line, I got this:
$ git push origin :in
fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.
This was likely due to pageant not having the private key loaded (which TortoiseGit loads automatically into pageant). Moreover, I noticed that TortoiseGit commands do not have the origin
ref in them (e.g. git.exe push --progress "my_project" interesting_local:interesting
).
I am also using Bitbucket and, as others web-based online git managers of the sort (GitHub, GitLab), I was able to delete the remote branch directly through their interface (branches page):
However, in TortoiseGit you may also delete remote branches through Browse References:
By right-clicking on a remote branch (remotes list) the Delete remote branch option shows up:
After deleting the old remote branch I pushed directly into a new remote branch through TortoiseGit just by typing the new name in the Remote: field of the Push window and this branch was automatically created and visible in Bitbucket.
However, if you still prefer to do it manually, a point that has not been mentioned yet in this thread is that -u
= --set-upstream
.
From git push
docs, -u
is just an alias of --set-upstream
, so the commands in the answers of Sylvain (-set-upstream new-branch
) and Shashank (-u origin new_branch
) are equivalent, since the remote ref defaults to origin
if no other ref was previously defined:
git push origin -u new_branch
= git push -u new_branch
from the docs description:
If the configuration is missing, it defaults to
origin
.
In the end, I did not manually type in or used any of the commands suggested by the other answers in here, so perhaps this might be useful to others in a similar situation.