Rename Local and Remote Branches in Git

To rename a branch in Git we should use the git branch command with -m option and run the following:

Case 1: If you want to rename the current local branch
 $ git branch -m your-new-branch

Case 2: If you want to rename another local branch
 $ git branch -m your-old-branch your-new-branch

Then delete your-old-branch on remote repository
 $ git push origin --delete your-old-branch

Finally, push your local branch to remote repository and reset the upstream branch with -u or --set-upstream option
 $ git push origin -u your-new-branch

gitrename branchrename remote branch

© 2019 4codev

Created with love by Sil.