


Renaming a remote branch requires pushing a new branch with the new name and deleting the old branch. Renaming a local branch is as simple as using the git branch command with the -m option. Renaming a Git branch, whether local or remote, is a straightforward process once you know the commands. To rename a local branch, you can use the git-branch command with the -m or -M option.
Git branch rename how to#
Again, you should see a confirmation message. This post will discuss how to rename a Git branch locally and remotely.
Push the new branch to create a new remote branch: git push originThis command pushes nothing to the remote server but deletes the old branch. When the branch you want to rename is your current branch, you dont need to specify the existing branch name. To fix this, remove the old branch by running the following command. However, the old branch will still be visible. git push origin -u Ĭheck your remote repository and you will find the new branch there. Then push the new branch to the remote repository. Instead, you need to push a new branch with the new name and delete the old branch.įirst, rename the branch name in the local repository with the above instructions. You can’t simply rename a remote branch using the git branch command because the branch lives on a remote server. Renaming a remote Git branch is a bit more involved. This command lists all the local branches, and you should see the new branch name listed. This repository is our up-to-date guidance on how and when to rename your default branch. We're committed to making the renaming process as seamless as possible for project maintainers and all of their contributors. You can confirm this by running the command: git branch GitHub is gradually renaming the default branch of our own repositories from master to main. After running this command, the branch name is updated. The -m option stands for “move,” which effectively renames the branch. Next, rename the branch using the command: git branch -m First, switch to the branch you want to rename using the command: git checkout It moves the branch from the old name to the new name. Renaming a local Git branch is a simple process. The -m is for move because this is what Git does under the hood. In this article, we’ll look at how to rename a Git branch, both locally and remotely.
