git - rename branch (local and remote)
#rename local branch
git branch -m old-branch-name new-branch-name
#delete remote branch with old name
git push origin :old-branch-name
#create remote renamed branch and setup remote branch tracking (-u flag)
git push -u origin new-branch-name
Nice and simple...
ReplyDeleteThanks, exactly what i was looking for. I would never have guessed the colon...
ReplyDeleteExcellent, a nice clear example.
ReplyDeleteShouldn't it be "git push -u origin new-branch-name"? Otherwise, it pushes the new-branch-name to the old name... Right?
ReplyDeleteNo, the difference of the "git push -u origin new-branch-name" is that it also sets up tracking of the remote branch for you local branch. It is usually better to add "-u" when you push the branch for the first time, but it still works without "-u".
DeleteBut without "-u" one will have to enter "git push origin new-branch-name" over and over again, whenever there will be a need to push.
DeleteI think that when I wrote this post I actually always used "git push origin branch-name" syntax.
DeleteBut now I use "git push -u" first time and then "git push origin HEAD", so I agree that this is better and I updated the post. And thanks for your comments!
Thanks Boris, Its so simple & Clear.
ReplyDelete