Git is commonly used as a version control system for any application. Which is helpful for tracking changes in any set of source files. A branch in Git represents an independent line of development with a unique set of code changes with a unique name.
This tutorial will help you to Rename a Git branch on a local repository. Also, we will apply the change to the remote git repository.
Rename a Git Branch in Local
You can use git branch -m
followed by branch name to rename a git branch on your local repository.
- First, switch to the branch you want to rename.
git branch <old_branch_name>
- Next, check the current active branch
git branch
An asterisk (*) symbol denotes the currently active branch.
- Finally rename a git branch with the following command. Before executing, make sure to replace the
<new_branch_name>
with your branch name.git branch -m <new_branch_name>
That’s it. You have successfully renamed the current branch in the local git repository. Again run git branch
to list branch names.
Rename a Git Branch on Remote
First, rename the branch name in the local repository with the above instructions. Then push the new branch to the remote repository.
git push origin -u <new_branch_name>
Check your remote repository and you will find the new branch there. However, the old branch will still be visible. To fix this, remove the old branch by running the following command.
git push origin --delete <old_branch_name>
Conclusion
This tutorial describes you rename a Git branch on local and remote repositories.
1 Comment
Thanks for the post