How do I rename a local Git branch?

To rename the current branch:

git branch -m <newname>

 

To rename a branch while pointed to any branch:

git branch -m <oldname> <newname>

 

To push the local branch and reset the upstream branch:

git push origin -u <newname>

 

To delete the remote branch:

git push origin --d <oldname>

 

To create a git rename alias:

git config --global alias.rename 'branch -m'

Tags:

git

Share:

Related posts