Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merge non-merged feature branch into another feature branch with Git

Tags:

git

merge

github

My company has a Git workflow that looks something like this:

  • Create feature branch from pristine branch (we use a base branch called "develop", but you can think of this as "master")
  • Do the work you need to do in this feature branch, and commit your changes
  • Occasionally, rebase your feature branch with the develop branch
  • When the work in your feature branch is complete, commit and push to the remote feature branch on GitHub
  • Create a pull request to merge your feature branch into the develop branch, which gets code reviewed by another developer
  • Once the code review is completed, the feature branch is merged into the develop branch, and the feature branch is deleted

This works when you're dealing with a serial workflow, but when you've pushed your changes from your feature branch and are waiting on the other developer to review and merge your changes, you probably want to take on another piece of work, which means repeating the above process.

In our case, we're currently creating our feature branches from the develop branch, so the work I just completed isn't yet available (it's still in limbo, waiting to be merged into the develop branch by another developer). The question I have is, what if the work I'm doing in my new feature branch depends on the work I just completed in my previous feature branch? Should I be initially branching my new feature branch from my as-of-yet unmerged feature branch instead of the develop branch? If I've already created my new feature branch from the develop branch, is getting the changes I'm missing from the unmerged branch as simple as doing a git merge [unmerged-branch] within my new branch?

Hopefully this explanation -- as well as the workflow itself! -- makes sense. I've gotten myself into some weird situations where I'm unclear the state of my code, so I'm trying to figure out a workflow that gives me the flexibility to merge in changes from other feature branches while still getting upstream changes at any time.

like image 642
Monkey34 Avatar asked Nov 21 '13 03:11

Monkey34


1 Answers

The question I have is, what if the work I'm doing in my new feature branch depends on the work I just completed in my previous feature branch? Should I be initially branching my new feature branch from my as-of-yet unmerged feature branch instead of the develop branch?

The way you're describing it, yes, you would. However, I'd be concerned about potentially going down the path of working off of "unapproved / unreviewed" work, as if your code review results in significant changes, you may find yourself redoing a lot of work.

If I've already created my new feature branch from the develop branch, is getting the changes I'm missing from the unmerged branch as simple as doing a git merge [unmerged-branch] within my new branch?

Yep. Should be. :)

like image 156
CDub Avatar answered Oct 17 '22 05:10

CDub