Rename a branch in git flow

Andrew Grimm picture Andrew Grimm · Apr 21, 2015 · Viewed 17.5k times · Source

Is it possible to rename a feature branch using git-flow?

I tried looking up git flow help and git flow feature help, and also the git-flow cheatsheet, but couldn't anything.

Alternatively, is it safe to just use git branch -m feature/new_name?

Answer

CodeWizard picture CodeWizard · Apr 21, 2015

Yep.

You can do it but if you pushed your branch and someone is using it you will need to update them about the change.

gitflow branches are no different then any other branch.

Rename local branch

Git beginner (Normal way)

#Checkout new branch and delete the old one
git checkout -b <new_name>
git branch -D <old_name>

#Use the short git branch move (-m flag)
git branch -m <old_name> <new_name>

#Use the short git branch move (–move flag)
git branch --move <old_name> <new_name>

Advanced: Manually rename branch

(Not recommended- aka Don't try it at home !!!)

Rename the old branch under .git/refs/heads to the new name
Rename the old branch under .git/logs/refs/heads to the new name
Update the .git/HEAD to point to your new branch name.

Sit back and Enjoy GIT :-)