Sam Hooke

Renaming Git branches

Following are some quick notes on how to rename a branch in Git, both remotely and locally. In the following examples we are renaming the branch old-name to new-name by copying the branch and then deleting the original. These notes assume you have one remote called origin.

Remotely duplicate the branch §

Copy the local branch old-name to origin, and rename it to new-name.

git push origin old-name:new-name

Locally checkout the new branch §

Configure a local branch which tracks the branch new-name at origin.

git branch new-name origin/new-name
git checkout new-name

Locally delete the old branch §

Delete the old branch locally.1

git branch -d old-name

Remotely delete the old branch §

Delete the old branch remotely (at origin).1

git push origin -d old-name

  1. The option -d is short for --delete↩︎ ↩︎

These are rough notes that vary greatly in quality and length, but prove useful to me, and hopefully to you too!

← Previous: Poetry: Offline installation of packages
Next: Managing multiple remotes in Git →