Renaming Git Branch

June 26, 2020

Renaming git branch in Terminal

Steps

  • Rename local branch
  • Push the renamed branch and delete the old branch in remote
  • Reset the upstream branch for the new-name local branch

To rename the current local branch, you can use

git branch -m new_name

If you're on other branch , you can use like

git branch -m old_branch_name new_branch_name

Push the renamed branch and delete the old branch in remote

To delete the old branch in remote and push the renamed branch to remote, you should use

git push origin :old_branch_name new_branch_name

Reset the upstream branch for the new-name local branch

git push origin -u new_branch_name

Second way to rename a branch

Steps to rename a branch

  • checkout to branch
  • rename local branch
  • push renamed branch & reset the upstream to new branch
  • delete old name branch

Checkout to branch

git checkout branch_name

Rename local branch

git branch -m new_branch_name

Push renamed branch & reset the upstream to new branch

git push origin -u new_branch_name

Delete old branch in remote

git push origin --delete old_branch_name