Articles

How To Rename A Local Git Branch

Let's say you have a branch on your local which you haven't yet pushed, but you named it the wrong thing, and you want to rename it. You can do this very simply with the following command:

git branch -m OLD_BRANCH_NAME NEW_BRANCH_NAME

If you're already on the branch you want to rename you can leave off the old name:

git branch -m NEW_BRANCH_NAME

The -m is for "move" because this is what Git does under the hood. It moves the branch from the old name to the new name, like the mv command in Linux does for files.

Hosted Gitea is a fully managed Gitea hosting service. If you're looking for a private alternative to GitHub or Gitlab check out our service.

Get your Gitea server