Rename Remote Branch In Git

Pavol Kutaj
May 1, 2021

--

The aim of this how-to-guide🏁 is to simply demo the rename of a remote branch.

1. steps/?

  • update the list or remote branches (and remove deleted ones), if needed
git remote update origin --prune
  • check out the remote branch
git checkout --track origin/<oldName>
  • Rename the checked-out branch:
git branch --move <new_name>
  • Push the <new_name> local branch and reset the upstream branch. Now you have 2 branches in remote. Both <old_name> and <new_name>
git push origin --set-upstream <new_name>
  • Delete the <old_name> remote branch. Note you don’t use git branch -D <name> at all (default cmd to delete a branch locally).
git push origin --delete <old_name>
  • Now you have 1 renamed branch in remote → Done

2. sources

--

--

No responses yet