Renaming a Local and Remote Git Branch
Sometimes you need to rename a Git branch, here are the simple commands rename a local or remote branch in Git using the command line.
Sometimes you need to rename a Git branch, here are the simple commands rename a local or remote branch in Git using the command line.
Updating Local Branch
-
Switch to the local branch you want to rename
git checkout <old branch name> -
Rename the branch by using the
-mflag:git branch -m <new branch name>**Note: if you have a branch matching
new branch nameuse the-Mflag to override the existing branch with the same name
Update Remote Branch
- Push the new branch, resetting upstream
git push origin -u <new branch name> - Delete the
old branch nameon the remotegit push origin --delete <old branch name>