36

I did git fetch and then git pull --rebase. It is trying to merge changes from the remote branch to my local branch. And there are some merge conflicts. So I did a git reset --hard.

My question is it is possible for me to ask git pull to take the remote change whenever there is a conflict?

1
  • Once can also fetch and then rebase manually (e.g. git fetch and git rebase -X theirs origin/foo)
    – Whymarrh
    Commented May 16, 2017 at 14:38

1 Answer 1

53

I think what you want is this:

git pull --rebase -s recursive -X ours

But it doesn't work (I'm using 1.7.0.4), even though the manpage says it should. I'm guessing this is due to the issue mentioned here.

Instead, you could use:

git pull -s recursive -X theirs

It works as expected, but you'll get a merge instead of a rebase.

Also - note 'ours', rather than 'theirs' when using --rebase. From the git-rebase manpage:

[CLIP]... a rebase merge works by replaying each commit from the working branch on top of the upstream branch. Because of this, when a merge conflict happens, the side reported as ours is the so-far rebased series, starting with upstream, and theirs is the working branch. In other words, the sides are swapped. ...[CLIP]

2
  • 1
    If I git pull --rebase upstream devel, wouldn't a --strategy recursive be redundant? The alternative would be the octopus merge strategy if I understand the manpages right, but it's only required if more than 2 branches are combined. In my case, there's only two (upstream/devel and <local>/devel, <local> being my working copy of fork/devel synced on Github). Thus, I would use git pull --rebase --strategy-option theirs if nothing speaks against it?
    – CodeManX
    Commented Aug 22, 2015 at 13:12
  • FWIW git pull --rebase -s recursive -X ours worked for me, thanks!
    – silvenon
    Commented Nov 6, 2020 at 9:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.