April 30, 2019
To rename the name of a branch, there are four potential steps:
git checkout <old_name>
git branch -m <new_name>
<old_name>branch to the remote repository delete the
git push origin --delete <old_name>
<new_name>local branch and reset the upstream branch:
git push origin -u <new_name>
That’s it. At this point you have successfully renamed your local and remote Git branch.
Similar to the
mv command in Bash, the
-m flag is for moving. Since you’re on a branch, Git infers the branch that’s being moved, however, you can be explicit and consolidate steps 1 and 2 with
git branch -m <oldbranch> <newbranch>.
Written by Stephen Weiss who lives in Chicago with his wife, Kate, and dog, Finn. Follow him on Twitter!