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?
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.
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.
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.
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