Changing a Git branch name is an essential task for developers to keep their workflows organized and maintain clarity in their codebase.
Whether you’re working locally or on a remote repository, the process to Git branch name change is simple yet crucial.
This guide will walk you through the steps of how to Git branch name change, including local and remote changes.
How Do I Git Change Branch Name?

Renaming a Git branch can be done using simple commands. Here’s how to Git change branch name locally:
Rename Local Git Branch
- First, ensure that you are not on the branch you want to rename. Switch to a different branch: bash
git checkout <another-branch>
- Rename the branch using the
-m
option: bashgit branch -m old-branch-name new-branch-name
This will Git change branch name locally from old-branch-name
to new-branch-name
.
How to Git Branch Name Change Remotely?
When you Git change branch name locally and remotely, you’ll need to push the renamed branch to your remote repository and delete the old branch.
Here’s how to Git change branch name both locally and remotely:
Rename and Push Remote Git Branch
- Rename your local branch as shown earlier.
- Push the renamed branch to the remote repository: bash
git push origin new-branch-name
- Set the upstream branch for the renamed branch: bash
git push --set-upstream origin new-branch-name
- Delete the old remote branch: bash
git push origin --delete old-branch-name
By following these steps, you will have successfully Git change branch name on both your local machine and remote repository.
How to Git Change Branch Name in GitLab?

Renaming a Git branch in GitLab is very similar to how you would do it in Git and other platforms. Here’s how to Git branch name Change in GitLab:
- Rename your local branch: bash
git branch -m old-branch-name new-branch-name
- Push the renamed branch to GitLab: bash
git push origin new-branch-name
- Delete the old branch from GitLab: bash
git push origin --delete old-branch-name
Now, GitLab will reflect the renamed branch after you Git change branch name.
Renaming a Git Branch in Bitbucket
For Git branch name Change in Bitbucket, the steps are similar to GitLab and GitHub. Here’s how to Git change branch name in Bitbucket:
- Rename the local branch: bash
git branch -m old-branch-name new-branch-name
- Push the renamed branch to Bitbucket: bash
git push origin new-branch-name
- Delete the old branch from Bitbucket: bash
git push origin --delete old-branch-name
This will complete the Git change branch name in Bitbucket.
Is It Safe to Git Change Branch Name?
Renaming a Git branch is generally safe, but there are a few things you need to consider:
- Collaborators: If you’re working with others, ensure that they are aware of the Git change branch name. They will need to update their local repositories.
- Fetch Changes: After renaming the branch, other contributors will need to fetch the updated branches using: bash
git fetch --all
It’s safe to Git change branch name, but make sure to communicate the change to your team.
How to Switch to Renamed Branch in Git?
Once you’ve renamed your branch, you’ll need to switch to it. You can do so using the git checkout command:
Switch to Renamed Branch
bashgit checkout new-branch-name
Alternatively, you can use git switch:
bashgit switch new-branch-name
These commands will help you switch branch name after you Git change branch name.
How to Get Branch Name in Git?
To check the name of your current branch, run the following command:
bash git branch
The active branch will be highlighted with an asterisk.
Git Rename File Command
If you want to rename a file in Git, use the git mv command:
bashgit mv old-filename new-filename
After renaming the file, remember to commit the change:
bashgit commit -m "Renamed file"
Reset the Upstream Branch After Git Change Branch Name

If you need to reset the upstream branch after renaming, use:
bashgit branch --unset-upstream
git push --set-upstream origin new-branch-name
This will reset the upstream branch for the renamed branch.
Conclusion
Renaming a Git branch, whether local or remote, is a straightforward process. When you Git branch name, it’s important to ensure you follow the correct steps to avoid confusion, especially with remote branches.
By following the instructions in this guide, you can safely Git branch name on your local machine and remote repositories like GitHub, GitLab, and Bitbucket.
For more details on working with Git branches, check out resources like the IONOS Git guide for in-depth instructions and troubleshooting tips.
FAQs
How Do I Git Change Branch Name?
To Git change branch name, use the following command to rename a branch locally:
bashgit branch -m old-branch-name new-branch-name
Then, push the renamed branch to the remote repository and delete the old branch:
bashgit push origin new-branch-name
git push origin --delete old-branch-name
How to Switch Branch Name in Git?
To switch branch name in Git after renaming it:
bashCopyEditgit checkout new-branch-name
Alternatively:
bashgit switch new-branch-name
Is It Safe to Git Branch Rename?
Yes, it is safe to Git change branch name, but always ensure that your team members are informed. If you’re working on a remote branch, delete the old branch from the remote repository to prevent confusion.
How Do I Change My Remote Branch Name?
To change remote branch name, rename the branch locally with:
bashgit branch -m old-branch-name new-branch-name
Then, push the renamed branch to the remote repository:
bashgit push origin new-branch-name
Finally, delete the old remote branch:
bashgit push origin --delete old-branch-name
How Do I Push a New Branch Name to GitHub?
To push a new branch name to GitHub, follow these steps:
- Rename your local branch with
git branch -m old-branch-name new-branch-name
. - Push the renamed branch: bash
git push origin new-branch-name