When I merge a branch in Git to master I often get merge conflicts. Is there a way to merge a branch and just overwrite the stuff in the current branch?
git pull --force it feels like it would help to overwrite local changes. instead, it fetches forcefully but does not merge forcefully ( git pull --force = git fetch --force + git merge ). Like git push, git fetch allows us to specify which local and remote branch we want to work on.
Rebase is one of two Git utilities that specializes in integrating changes from one branch onto another. The other change integration utility is git merge . Merge is always a forward moving change record. Alternatively, rebase has powerful history rewriting features.
Add -X ours
argument to your git merge
command.
Say you are working in your local branch. Then you want to merge in what went in the master
:
git merge -X ours master
On the other hand if you are in master
and want to merge your local branch into master
then @elhadi rightly says you should use theirs
:
git merge -X theirs somebranch
To overwrite your stuff in your branch and take their work, you should make
git merge -X theirs {remote/branch} --> example:origin/master
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With