Search code examples
gitgit-mergegit-remotegit-configgit-merge-conflict

Configure merge options for a particular remote repository in git?


I'd like to use a particular merge option ('ours') for the recursive strategy when pulling from a particular remote repository, but not others.

I know about git config branch.<name>.mergeoptions "-Xours", but that's per-branch rather than per-remote repository.

The use case, if it's helpful: I am making a project template that I would like to be able to clone when starting a new project. After working on the project for a while, I'd like to be able to merge in any non-breaking changes from the template with the assumption that conflicts should default to the project and not the template.

Any help in accomplishing this would be great.


Solution

  • There's no "use this on pull" option but if you can retrain your own fingers, it's trivial to do manually.

    What git pull does is simply (ok, complicated-ly1 :-) ) run git fetch followed by git merge. Just do this yourself, or provide yourself an alias or script that does this, and adds -X ours at the merge step. Run that instead of git pull and you're done.


    1The complications mostly come from (a) historical baggage, from the days before "remotes" even existed or were used the way they are now, and (b) the fact that you can configure the script to run git fetch followed by git rebase instead.