How to Change Branch Name in Git?
Last Updated :
20 May, 2024
Git is a powerful version control system widely used for managing code changes in software projects. One common task that developers encounter is renaming branches. Whether due to a change in project scope, a shift in naming conventions, or a simple typo, knowing how to rename branches efficiently is an essential Git skill. This guide will walk you through the steps to rename both local and remote branches in Git.
Why Rename a Branch?
Renaming a branch can be necessary for several reasons:
- Correcting Typos: Fix any spelling mistakes in the branch name.
- Adopting Naming Conventions: Ensure branch names adhere to team or project naming standards.
- Clarifying Purpose: Make the branch name more descriptive and meaningful.
Steps to Rename a Local Branch
Renaming a local branch in Git is straightforward. Follow these steps:
Step 1: Switch to the Branch
Ensure you are on the branch you want to rename. If not, switch to it using
git checkout -b old-branch-name
//Replace old-branch-name
with the current name of your branch.
Suppose, In my system their is already a branch with the name 'Geeks', Then I will simply checkout or moved to that.

Step 2: Rename the Branch
Use the git branch -m
command to rename the branch. In this example, I want to change my branch name from 'Geeks
to
'GeeksforGeeks'
git branch -m new-branch-name
// Replace new-branch-name
with
// the desired new name for the branch.

Step 3: Verify the Renaming
To confirm the branch has been renamed, list all branches:
git status
You should see the new branch name listed.

Renaming a Remote Branch
Renaming a remote branch involves a few more steps than renaming a local branch. Follow these steps:
Step 1: Rename the Local Branch
First, rename the local branch as described above.
Step 2: Delete the Old Branch on the Remote
Push the renamed branch to the remote repository and delete the old branch:
git push origin new-branch-name
git push origin --delete old-branch-name
Replace new-branch-name
with the new branch name and old-branch-name
with the old branch name.
Step 3: Reset the Upstream Branch
Set the upstream branch for the renamed local branch:
git push --set-upstream origin new-branch-name
Handling Branch Renaming in Collaborations
When working in a team, it's important to communicate branch renaming to avoid confusion. Here are a few tips:
- Notify Team Members: Inform your team about the branch name change through your communication channels.
- Update Documentation: Ensure any documentation that references the old branch name is updated to reflect the new name.
- Coordinate Timing: Coordinate the renaming process to minimize disruptions, especially if your team is actively working on the branch.
Conclusion
Renaming branches in Git is a simple yet powerful capability that helps maintain clarity and organization in your version control system. By following the steps outlined in this guide, you can efficiently rename both local and remote branches, ensuring your project stays clean and well-managed. Whether correcting a typo or adopting a new naming convention, mastering branch renaming is an essential skill for any developer using Git.
Similar Reads
How to Rename Branch in Git?
Renaming branches in Git is important for keeping your repository organized and understandable, especially when collaborating with others. Clear and descriptive branch names improve project management and help team members identify the purpose of each branch. Renaming branches also ensures consisten
1 min read
How to Create a New Branch in Git?
Git is a powerful and widely used version control system that helps developers manage code changes across projects efficiently. One of the fundamental features of Git is branching, which allows developers to diverge from the main line of development and work on different tasks or features independen
4 min read
How to Check Branch in Git?
In Git, branches are independent lines of development that allow you to work on features or fixes without affecting the main codebase. Checking branches is important for managing project history, coordinating collaboration, and ensuring smooth development workflows. This article will walk you throug
2 min read
How To Get The Current Branch Name in Git?
In Git, a branch represents an independent line of development. When working with Git, it's often necessary to know which branch you're currently on. This can help you avoid making changes in the wrong branch and ensure you're following your workflow correctly. This article will cover various method
2 min read
How To Create Branch In Git?
Creating branches in Git is a fundamental skill for any developer. Branches allow you to work on different features, bug fixes, or experiments in isolation from the main codebase. This way, you can keep your main branch stable while making changes on separate branches. In this article, weâll guide y
2 min read
How to Checkout New Banch in Git?
Git provides powerful features for managing code changes, collaborating with teammates, and organizing development workflows. One essential task in Git is checking out new branches, which allows developers to work on isolated features, fix bugs, or experiment with changes without affecting the main
2 min read
How to Clone a Branch in Git?
Git is a popular version control system that allows developers to track changes in their code and collaborate with others. Cloning a branch in Git involves creating a copy of a specific branch from a remote repository. This article will guide you through the process of cloning a branch in Git. Table
3 min read
How to Checkout Remote Branch in Git?
When working on collaborative Git projects, managing different versions of your code through branches is crucial. Often, developers need to switch between branches, especially remote ones, to work on specific features or bug fixes. In this comprehensive Git tutorial, weâll teach you how to easily ch
5 min read
How to Manage Branches in GitLab?
GitLab is a web-based platform (like GitHub) that provides services related to the version control system of a project. Branching is one such concept of the version control system. Note: Make sure you have created a GitLab account and a repository. These are the following approaches to Manage branch
3 min read
How To Fetch Remote Branches in Git ?
Git provides a powerful version control system that allows developers to collaborate efficiently on projects. Over time, however, a repository can have local and remote branches. Local branches are created locally and only exist on local machines and the remote branches exist on the remote repositor
3 min read