Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merging but overwriting changes in Git

Tags:

git

conflict

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?

like image 961
John Hunt Avatar asked Jan 11 '13 10:01

John Hunt


People also ask

Does git pull merge or overwrite?

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.

Does git merge rewrite history?

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.


2 Answers

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 
like image 110
kmkaplan Avatar answered Oct 06 '22 08:10

kmkaplan


To overwrite your stuff in your branch and take their work, you should make

git merge -X theirs {remote/branch} --> example:origin/master 
like image 28
elhadi dp ıpɐɥןǝ Avatar answered Oct 06 '22 07:10

elhadi dp ıpɐɥןǝ