Temporarily use commits from another feature branch

My git flow looks like the following:

                        x - x (feature/branch-a)
                      /
(master) x- x (develop) 
                      \
                        x - x (feature/branch-b)

There is currently a commit and PR for branch-a to develop. I'll be waiting a bit before branch-a PR is accepted but branch-b reuses quite a bit of logic from branch-a that I need.

Before I start copying code from branch-a to branch-b, is there a better way to merge this code without creating a feature branch-b off branch-a.


I would highly recommend taking the fancy rebase approach described in eftshift0's comment. It's not trivial because you first need to learn and become comfortable with doing git rebase --onto. But once you really git it, you can surgically move your commits around a repo at will.

With that in mind, it actually doesn't matter if you merge feature/branch-a into feature/branch-b right now, or rebase B onto A right now like you said you wanted to avoid. Both methods will enable you to keep working, and once A's PR is merged into develop you can just fancy rebase your own commits onto the latest develop in preparation for your PR. Note you don't have to rebase and clean up your branch before your PR, but if you don't, you may be pulling in duplicate commits (that differ only by commit ID) from an older version of feature/branch-A, and possibly conflicting with them too.

Side Note: one of the gotchas when you first learn a fancy rebase is that if you use it with commit IDs instead of branch names, when you're done you end up detached. If you find yourself in that situation, to set your branch to your desired commit, after the rebase is done you can just run the command:

git checkout -B feature/branch-b

Note the checkout -B means create the branch and overwrite if it already exists.