How to Rename Branch in GIT

  • Rename currently checked-out local branch
git branch -m <new-branch-name>
  • Rename local branch
git branch -m <branch_name_to_rename> <new-branch-name>
  • push new branch name to remote
git push origin :<old_name> <new_name>
  • Rename branch locally and remotely in 3 steps
# Rename branch locally
git branch -m <old-branch-name> <new-branch-name>
# Delete the old branch
git push origin :<old-branch-name>
# Push the new branch, set local branch to track the new remote
git push --set-upstream origin <new-branch-name>
OR
git push -u origin <new-branch-name>
  • Reset the upstream branch for the new-name local branch.
    • Switch to the branch
      • git checkout <new_name>
    • Push new branch-name now
      • git push origin -u new-name

* The Content stated above is for informational purpose only. Expert Software Team is not responsible if any part of content found meaningless in any manner or condition.

Leave a Reply

Your email address will not be published. Required fields are marked *