Git Branch Renaming

Git Episode-1

Version control systems are a handy tool in software development while we are collaborating with multiple people in a project. Git is a widely used version control system around the world. You may refer this to get more details about git and version control systems.

Branching is a cool feature in version control systems. Branching allows us to work in the same project without disturbing our other collaborator of the project. When we are working that manner, we may have some naming convention to keep things clear. When we create a branch in the local or remote version control system, We may create a branch with the wrong name or without obeying the naming convention of the working company or the developing team. So we must rename the branch in local and remote repositories to be followed the correct naming policy of the team or the working company.

Photo by Yancy Min on Unsplash

I am guiding you this process through four steps.

  1. Initially, we start by switching to the local branch that we want to rename.
git checkout <old_branch_name>

2. Then we have to rename the local branch by using the below command.

git branch -m <new_branch_name>

Here, We rename the local branch. Anyhow, If we already pushed our changes with the old branch name to the remote repository, We have to rename that also.

3.we Push the new local branch and reset the upstream branch to the new branch name.

git push origin -u <new_branch_name>

4. Then we must delete the old remote branch to avoid confusion.

$git push origin --delete <old_branch_name>

If you can go through these four correctly, the expected branch name will be successfully changed to the new name.

I believe that you understood the topic that I discussed today. If you have any doubts or want any clarification, don't hesitate to contact me through the response section. Thank you for spending your precious time to read this article.


Photo by Kelly Sikkema on Unsplash




Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Thenusan Santhirakumar

Thenusan Santhirakumar

Writer 🖊️ | Software Engineer 👨‍💻 | SE Intern @ WSO2 IAM 👨‍💻🔑 | Undergraduate👨‍🎓📚 | Computer Science & Engineering 💻⚙️ | UOM 🏫📚