Rename a branch in git flow
Asked Answered
S

3

25

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?

Sastruga answered 21/4, 2015 at 0:13 Comment(1)
checkout this #704002Compurgation
C
47

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 long 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 :-)
Cathedral answered 21/4, 2015 at 2:18 Comment(2)
In order to really understand things, I'd also need to understand what exactly git-flow is and what it does. In particular, whether git-flow stores information of its own anywhere.Sastruga
You right, there is no need to understand what is going on beyond the scenes unless you are interested in knowing how git does the magic. the simple answer to your question is yes, rename it but update your development team that renamed the branch if any of then already pulled it out from your main server.Cathedral
P
21

You can use git-flow feature rename NewFeatureName to rename a feature.

This seems to be not very well documented. You can find the reference here

Pooch answered 19/4, 2020 at 21:55 Comment(1)
Seems good, even though it does not support rename of release branchesTrillbee
R
9

Yes, but if you use gitflow you also need to manually modify (I don't know if there is an automatic way to do that) the file .git/config, and rename the git-flow feature name for the feature you want to rename

Rika answered 10/11, 2015 at 11:49 Comment(1)
Nothing in the .git/config that has the actual feature name. Only that features have feature/... in their branch name.Jaynajayne

© 2022 - 2024 — McMap. All rights reserved.