Search code examples
gitbranchbranching-and-mergingfeature-branch

How does one work on a new git branch that depends on another git branch that is not yet merged?


Here's my scenario:

  • My project is following the topic branching pattern.

  • I create a branch to fix some problems, let's call this branch problem_fixes. I make my changes, and submit a pull request.

  • I need to start work on a new feature, so I create a second branch called my_feature and commit a bunch of changes.

  • At some point I realize my_feature is dependent on problem_fixes which has not yet been accepted and merged (the my_feature branch relies on some of the fixes from the first branch and I can't make progress without them).

Short of badgering my project lead to accept and merge my first branch faster, what is the best process to follow here?

I am wondering if I need to start a new, third branch based on problem_fixes (instead of master) and merge in my commits to my_feature? Or will it be okay if I simply merge problem_fixes into my_feature and continue work -- assuming problem_fixes is merged into master first, when my_feature is merged it should theoretically be okay(?)


Solution

  • Yes, I think you're on the right track. What I would do is create a new my_feature branch, perhaps work a little bit. When I realise that my_feature depends on problem_fixes, merge that branch in. This could happen right away if you know that you'll need it. Then, when my_feature is merged into master, you'll already have the changes you need.

    Note that as long as you have a robust code review procedure, then if you try to merge my_feature into master before problem_fixes, then you will notice at that time.