Git flow - create feature branch off another feature branch
Asked Answered
R

5

93

I having been using git flow for a while now. I am curious to learn about a specific use case.

For one of my projects I have a ticket for a new website feature. This ticket depends on many sub-tasks. I would like to create a feature branch for the main ticket, and then for each sub-task create a feature branch off of the parent feature branch.

Let's assume I have a ticket PROJ-500 and I create a feature branch for it

git flow feature start PROJ-500

Then I want to integrate tickets PROJ-501 through PROJ-515 into PROJ-500 before integrating the whole thing into develop. Is there a way for me to do something like

git flow feature start PROJ-511 -b PROJ-500

Then over time these sub-tasks get completed and when their feature is finished, the branch is merged into PROJ-500.

git flow feature finish PROJ-511

The above command would merge PROJ-511 into PROJ-500

And once all sub-tasks are completed then PROJ-500 will be finished and merged into develop.

This way the new website feature is integrate into develop as a single unit rather than piecemeal.

Rowley answered 8/4, 2014 at 21:41 Comment(1)
Does this not do it? git flow feature start PROJ-511 PROJ-500? The link you posted in the comment to DerekS' answer suggests that it should.Rajewski
W
131

You can create a sub-feature branch via

git flow feature start PROJ-511 feature/PROJ-500

But you cannot use the GitFlow tool to merge the branch back into the main feature branch because if you do

git flow feature finish PROJ-511

the feature will be merged into develop. Ergo sub-features are not supported, you need to do it manually.

Alternatives: The requirement is not new, though. There is an open issue as well as a fork project claiming to support finishing features into branches other than develop. I also found a pull request with an implementation of that feature. You might want to try that modification and see if you are happy with it.


Update 2019-12-13: As user Matěj Kříž just mentioned in his comment, user Tony Chemit has written an answer here a few months after mine, pointing to gitflow-avh as an alternative to the original gitflow product. It supports sub-features out of the box with the syntax shown above. Some years have passed by and nowadays the AVH edition is part of the normal installation of Git for Windows, I just verified this on my local box and tested the sub-feature option. I.e. for Windows users it just works right after Git installation.

Wald answered 8/12, 2014 at 13:54 Comment(4)
@pymarco: Thanks for accepting the answer. I am curious though: Have you tried any of the alternatives? If so, which one and what was the outcome? Does it work as expected? Maybe other readers can learn something from your experience. :-)Wald
Sorry, but I have not had time to return to this. I will try at some point.Rowley
Why the downvote? Downvotes are meant to be used for badly written, sloppy answers showing no sign of research effort or knowledge. Anyway, thanks.Wald
If you use gitflow-avh version look lower at https://mcmap.net/q/224244/-git-flow-create-feature-branch-off-another-feature-branch @tony-chemit answerEuphemie
H
38

As I understood, gitflow is quite abandoned.

gitflow-avh replaces it and offers this feature (see https://github.com/petervanderdoes/gitflow#creating-featurereleasehotfixsupport-branches).

I just try it and it works well to me.

git flow feature start PROJ-511 feature/PROJ-500
git flow feature finish PROJ-511

PROJ-511 was merged into feature/PROJ-500.

Haywire answered 30/3, 2015 at 18:44 Comment(0)
M
16

As already mentioned, we can start a new feature using any base branch with

git flow feature start PROJ-511 feature/PROJ-500

And to finish the sub feature we can temporarly change git flow configuration to use our feature branch instead of develop:

git flow config set develop feature/PROJ-500 && git flow feature finish PROJ-511

This way, git flow runs all commands and sanity checks. Finally, To restore config, we can run

git flow config set develop develop 
Massimiliano answered 6/6, 2016 at 23:29 Comment(0)
M
8

Update (November 5, 2020): As noted in the newer answer here, this is possible with gitflow-avh which has replaced the original git flow.

===================

Original Answer:

I don't think there is a method for this in git flow, but it is fairly simple with just git.

git checkout PROJ-500
git checkout -b PROJ-511
...do your PROJ-511 work...
git checkout PROJ-500
git merge PROJ-511
git branch -d PROJ-511
Muezzin answered 8/4, 2014 at 21:55 Comment(1)
Thanks Derek for responding. Yes, I could follow that workflow. But git flow encapsulates a number of commands and sanity checks that I prefer to utilize for sub-feature development. For example here is a link to git-flow-feature - github.com/nvie/gitflow/blob/develop/git-flow-featureRowley
E
0

Simply you can make it from a base feature or even a branch as you like

git flow feature start new-feature-name original-feature-or-base-branch
Electuary answered 8/7, 2022 at 12:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.