How to merge git commits in the develop branch to a feature branch How to merge git commits in the develop branch to a feature branch git git

How to merge git commits in the develop branch to a feature branch


To integrate one branch into another, you have to either merge or rebase. Since it's only safe to rebase commits that aren't referenced anywhere else (not merged to other local branches; not pushed to any remote), it's generally better to merge.

If your feature branch is purely local, you can rebase it on top of develop. However, it takes time to understand how rebase works, and before you do, it's quite easy to accidentally produce duplicated or dropped commits. Merge commits might look noisy but merging is guaranteed to always be safe and predictable.

For a better view, try logging everything together in a graph:

git log --all --graph --oneline --decorate

It's also worth considering whether you really need the commits on develop merged into feature. Often they're things that can be left seperate until feature is merged into develop later.

If you regularly find you do need develop code on feature then it might be a sign that your feature branches are too long-running. Ideally features should be split in such a way that they can be worked on independently, without needing regular integration along the way.


If you only want one commit from the develop branch you can cherry-pick it in your feature branch:

 git checkout feature git cherry-pick -x <commit-SHA1>

The commit will be applied as a new one on top of your branch (provided it doesn't generate a conflict), and when you'll merge back the feature branch Git will cope with it without conflicts.