Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make remote branch take precedence during a merge conflict

Tags:

git

I have two branches, current and master. current is dozens of commits ahead of master so I think it's time to merge.

I change to master

git checkout master

I attempt to merge with current

get merge current

I get about 20 conflicts of this nature:

CONFLICT (rename/add) <remote>
CONFLICT (rename/add) <remote>

First question, how do I make the remote branch, current take precedence here? I'm working my way through all the conflicts with git mergetool -t meld and I'm clicking away, selecting all the remote changes over the local changes.

So how can I do this with one command? I want remote to take presence.

Also, why have these conflicts occurred? I would have thought it obvious that the latest branch would contain the changes we want to keep?

like image 621
Starkers Avatar asked May 02 '14 10:05

Starkers


People also ask

What happens if you get a conflict during a merge?

Merge conflicts happen when you merge branches that have competing commits, and Git needs your help to decide which changes to incorporate in the final merge. Git can often resolve differences between branches and merge them automatically.

Does Git merge affect remote branch?

The short answer is simple: no, the remote-tracking branch remains unaffected. A good way to think about a remote-tracking branch like origin/master is that your git remains independent of their (origin's) git almost all of the time, except for when you tell your git to call up their git and coordinate.


1 Answers

When you are merging you can specify a strategy to use for automatically resolving some conflicts (the comments contain a link to the man page for this http://git-scm.com/docs/git-merge). You would use the recursive strategy with the option of theirs. This will resolve all conflicts by using the version in the branch that is being merged in. If you were merging master into your branch, then it would be ours.

The command would end up being:

git merge -s recursive -Xtheirs current

This will resolve ALL conflicts with what is on the branch being merged in.

Before you commit your merge if there are conflicts, I would check the diff with git diff --staged carefully. And run any tests that you have so that you are sure that the conflict resolution didn't overwrite changes on master that you actually wanted.

like image 172
Schleis Avatar answered Oct 11 '22 05:10

Schleis