How to rename a local and remote branch in Git?

Shit Happens!! Sometimes, you named a branch wrong or want to make it more meaningful. Doing it locally is quite simple.

Shit Happens!! Sometimes, you named a branch wrong or want to make it more meaningful. Doing it locally is quite simple:

git branch -m new-branch-name

In case you are on a different branch, you can do it like this:

git branch -d old-branch-name new-branch-name

Rename the git branch on remote.

In some cases, you might have pushed your branch to remote, too; for that, you can run the following command to rename it on remote too:

git push origin :old-branch-name new-branch-name

To reset the upstream branch for the newly named local branch

Switch to the branch and then run the following command:

git push origin -u new-branch-name

Originally Posted On: MultipleStates

Subscribe to GIT.WTF!?!

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
[email protected]
Subscribe