On my Git repository, I have a feature branch and a master branch. I want to merge the two. For convenicence, however, I would like to keep the feature branch and contiune development of the feature without creating a new branch. That is, I would like to have the following structure:
Master M0 --- M1 --- M2 --- M3 --- M4
\ / \
Feature F0 ---- F1 ---- F2 F3 --- F4
The recent state F4
of the feature branch shall include all changes to master up to state M3
.
My understanding was that git merge
would do exactly this. However, after trying this out another time, I receive the message that the feature branch is a couple commits behind the master branch. Is this expected or is there an error somewhere? If this is the expected behaviour, how do I achieve what I want?
You can merge master into the feature branch first:
$ git switch feature
$ git merge master # Apply all changes in master to feature
$ # (At this step, you might want to do some testing to make sure the merge didn't cause any new bugs)
$ git switch master
$ git merge feature # Apply all changes in the feature branch back to master
In fact, you should always merge master into any other branch before merging the result back into master. This way you can correct any merge conflicts in your feature branch while making sure master always stays functional.