Git branch renaming

Why rename the branch?

Recently I was working on a branch to add a small amount of functionality. I got a bit carried away with refactoring some of the code that needed doing, but it was introducing some breaking changes. I’d coordinated with other members of the team to assure we coordinated the reconfiguration work that needed to be done after changes, so that was fine. However, further into the day I realised that we needed to get some of the functionality deployed but I couldn’t push all of the changes.

I’d already pushed the branch to the main repo, but the name of the branch was appropriate to what we wanted to merge now. Fortunately, a quick Google and a useful result here, and I had my solution.

How to rename local and remote branches

Checkout the local branch to rename and rename it

$ git checkout <branch to rename>
$ git branch -m <new branch name>

Push the new branch up to the central repo

$ git push -u origin <new branch name>

Delete the old remote branch

$ git push origin --delete <old branch name>
Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *