How can I rename a local Git branch?

115    Asked by LynettaWillett in Devops , Asked on Sep 4, 2025

How can you rename a local Git branch without losing your work, and what commands should you use to do it safely? Learn the step-by-step process to rename the branch you’re currently on or another branch in your repository.

Answered by Justin Stewart

Renaming a local Git branch is a straightforward task, but it’s important to know the right commands so you don’t accidentally lose track of your work. Git allows you to rename both the branch you’re currently on and any other local branch, but the commands differ slightly.

If you want to rename the branch you are currently on, you can use:

  git branch -m new-branch-name

If you want to rename a different branch (not checked out), you specify both the old name and the new name:

  git branch -m old-branch-name new-branch-name

Here are some key points to keep in mind:

  • -m stands for move – This tells Git to move (rename) the branch.
  • Make sure the branch exists – Double-check branch names with git branch.
  • No data is lost – Renaming only changes the branch pointer name, not your commits.

Remote branches are separate – Renaming a local branch won’t automatically update the remote. If the branch is already pushed to a remote, you’ll need to delete the old one and push the new one:

 git push origin ld-branch-name
git push origin new-branch-name
git push --set-upstream origin new-branch-name

 In short, renaming a local Git branch is safe and easy. Just use git branch -m for local changes, and if the branch is tracked remotely, don’t forget to update the remote reference as well.



Your Answer

Interviews

Parent Categories