Rename a branch in Git

CLI

Git

Branch

Rename

Luc B.

Git

Branch

Sometimes you type in your branch name wrong, or you choose a branch name that's already in use in your remote repository. Luckily, Git branch names are easy to change.

Code Example

Use the -m flag to git branch to change the current branch name.

# Change the current branch name to 'new-branch-name'
git branch -m new-branch-name

In addition, by passing two branch names, you can change the name of branches that aren't currently checked out.

# Change the 'master' branch to 'new-branch-name'
git branch -m master new-branch-name