Rename a Branch

When you want to rename a Git branch, you can use the Rename Branch option to change the name of your local branch, then push the renamed branch to the remote repository.

Note:

Exercise caution when renaming branches, especially if other team members are still using those branches. Renaming the default branch (main, for example) might break build scripts that your repository uses. Before you rename the branch, you'll want to update references to the old branch name in your code or scripts.

Renaming a branch changes your current branch's name while keeping its history and pushes the renamed branch to remote, but the current remote branch is not renamed or deleted. Suppose your current branch is mybranch and you want to change its name to newbranch, the rename first replaces the local mybranch with newbranch, then pushes the local newbranch to the remote repository. No changes are made to mybranch, the previous existing remote branch. You'll have to manually delete this remote branch if you want to.

If the branch you want to rename is local (that is, it isn't tracking a remote branch), the branch is renamed, but isn't automatically pushed to the remote repository—the branch stays local even after the rename.

To rename a branch:

  1. Click the Git menu in the header and select Rename Branch.
  2. In the Rename Branch dialog, enter a new name for the branch. Make sure you're not using the name of an existing branch.
  3. If the current branch has any uncommitted changes, you have the option of committing those changes.
    • To commit your changes before renaming the branch, enter a commit message (with the Commit changes before renaming branch check box selected).
    • To rename the branch without committing your changes, deselect the Commit changes before renaming branch check box.
  4. If you chose to commit changes, click Commit All and Rename; otherwise, click Rename Branch.

    When the rename is successful, close the confirmation message that appears.

The renamed branch shows up in the header as your current branch.