How to Rename Local Branch in Git
- Method 1: Renaming the Current Branch
- Method 2: Renaming a Different Branch
- Method 3: Using Git GUI Tools
- Conclusion
- FAQ

Renaming a local branch in Git is a common task that many developers encounter. Whether you want to correct a typo, make the branch name more descriptive, or simply reorganize your workflow, knowing how to rename branches effectively can save you time and confusion.
In this tutorial, we will explore different methods for renaming a local Git branch, complete with clear commands and explanations. By the end of this article, you’ll have a solid understanding of how to manage your branches more efficiently, ensuring that your project remains organized and easy to navigate.
Method 1: Renaming the Current Branch
If you find yourself on the branch you want to rename, Git makes it easy to rename it with a simple command. Here’s how you can do it.
git branch -m new-branch-name
Output:
Branch renamed to 'new-branch-name'
This command uses the -m
option, which stands for “move,” allowing you to rename the current branch directly. Simply replace new-branch-name
with your desired name. It’s worth noting that this method is straightforward and does not require you to switch branches. This is particularly useful when you’re deep into development and want to keep your focus without unnecessary context switching.
One thing to keep in mind is that if you have already pushed this branch to a remote repository, you’ll need to delete the old branch from the remote and push the new one. This can be done using:
git push origin :old-branch-name
git push origin new-branch-name
Renaming your current branch is a quick and efficient way to keep your branch names relevant to your work, enhancing clarity for both you and your team.
Method 2: Renaming a Different Branch
Sometimes, you may want to rename a branch that you are not currently on. Git allows you to do this as well, providing a seamless experience for managing your branches.
git branch -m old-branch-name new-branch-name
Output:
Branch 'old-branch-name' renamed to 'new-branch-name'
In this command, you specify both the old and new branch names. This method is particularly useful when you want to make changes to a branch that is not currently checked out. Just ensure that the old branch name exists; otherwise, Git will return an error.
After renaming, if you want to update the remote repository, you will need to push the new branch and delete the old one, similar to the previous method. This ensures that everyone collaborating on the project is aware of the changes made to the branch names.
Renaming branches can help maintain a clean and organized repository, making it easier for team members to understand the purpose of each branch at a glance.
Method 3: Using Git GUI Tools
If command-line interfaces aren’t your preferred method, you can also rename branches using Git GUI tools. Many developers find graphical interfaces more intuitive, especially when managing multiple branches.
Most Git GUI tools, such as GitKraken, SourceTree, or even the built-in Git functionality in IDEs like Visual Studio Code, provide an easy way to rename branches through a visual interface.
To rename a branch in a GUI tool, you typically need to:
- Navigate to the branch management section.
- Right-click on the branch you want to rename.
- Select the option to rename the branch.
- Enter the new name and confirm.
While this method does not involve command-line syntax, the underlying principles remain the same. The GUI will handle the renaming process and any necessary updates to the remote repository.
Using GUI tools can simplify the process for those who are less comfortable with the command line, making Git more accessible for everyone.
Conclusion
Renaming local branches in Git is a simple yet essential skill for any developer. Whether you prefer command-line methods or graphical interfaces, Git provides multiple ways to keep your branch names organized and meaningful. By following the methods outlined in this tutorial, you can ensure that your branches reflect the work being done, thereby enhancing collaboration and clarity within your team. Remember to always update your remote repository after renaming branches to keep everything in sync.
FAQ
-
How do I check which branch I am currently on?
You can check your current branch by running the commandgit branch
. The active branch will be highlighted with an asterisk. -
Can I rename a branch that has unmerged changes?
Yes, you can rename a branch with unmerged changes. However, ensure that you are aware of any pending changes before renaming. -
What happens to the old branch after renaming?
The old branch will no longer exist under its previous name, but if it was pushed to a remote repository, you will need to delete it manually. -
How do I delete the old branch from the remote repository?
You can delete the old branch from the remote by using the commandgit push origin --delete old-branch-name
.
- Is there a way to rename multiple branches at once?
Git does not provide a built-in command to rename multiple branches simultaneously, but you can script the process using a loop in your terminal.
Abdul is a software engineer with an architect background and a passion for full-stack web development with eight years of professional experience in analysis, design, development, implementation, performance tuning, and implementation of business applications.
LinkedIn