Web Hosting in Pakistan

How to rename a GIT Branch?

While managing your group work in GIT, have you missed naming the local or remote repository file in the decided format? So, does that mean your group members won’t find the desired file now? Well, this could be the case but luckily, you can rename a GIT branch.

What’s the process?

You can use the “GIT branch -m command” for renaming purposes.

Here’s how you can rename the local branch.

Find the local branch you want to rename. You can do this by using the following command:

git checkout <old_name>

Now rename the old file based on the naming conventions you have decided with your group members. Here’s the command to do so:

git branch -m <new_name>

But what if you have pushed the branch to the remote repository? Now the process would have to be a bit different. Here’s what you have to follow:

You’ll have to push the new name in the remote repository for this file. You can use the following command to do so:

git push origin -u <new_name>

Once done, you can delete the old name of the file. Here’s the command that can help you:

git push origin --delete <old_name>

Summing Up:

Renaming the local GIT Branch is a matter of a single command but once it transfers to the remote repository, you’ll have to push the old name with a new one to complete the naming process.