Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git flow - create feature branch off another feature branch

Tags:

git

git-flow

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.

like image 759
pymarco Avatar asked Apr 08 '14 21:04

pymarco


People also ask

Can we create feature branch from another feature branch?

Use the git checkout Command to Create Branch From Another Branch in Git. Git, a distributed version control system, is a useful tool for tracking changes to the project repository. We have multiple team members or teams using the same project repository for work in a collaborative development environment.

Can you branch off a feature branch in git?

No, but you won't be able to merge your work into develop without merging also the commits from the feature branch. If feature branch is merged when you finally merge your own work to develop , all the common commits won't be merged twice.

How do I merge a feature branch to another feature branch?

Merge branchesSelect the branch that you want to merge into the current branch, click Modify options and choose from the following: --no-ff : a merge commit will be created in all cases, even if the merge could be resolved as a fast-forward.

Can we merge two feature branches in git?

To merge branches locally, use git checkout to switch to the branch you want to merge into. This branch is typically the main branch. Next, use git merge and specify the name of the other branch to bring into this branch. This example merges the jeff/feature1 branch into the main branch.


1 Answers

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.

like image 53
kriegaex Avatar answered Sep 20 '22 18:09

kriegaex