3days since the last Git and AI fuck-up

How to rename a local and remote branch in Git?

Mandeep Singhfrom the archive

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

shell
git branch -m new-branch-name

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

shell
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:

shell
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:

shell
git push origin -u new-branch-name

Originally Posted On: MultipleStates

Tagged mistakes-correction, git-branch, git-remote, local