code_fodder code_fodder - 18 days ago 6
Git Question

Git setting up standard merge tool for the project in the repo itself

So, following on from this (and other) question/answers: git-on-windows-how-do-you-set-up-a-mergetool, which tells us how to setup a diff/merge tool on your local PC (either globally or per project).

For our project (where we are standardising our toolsets and installtions) I want to setup the diff / merge tool just once and roll it out to everyone.

Is there a way to do this? - i.e. when we clone a project it comes with the merge/diff tool config already in it.

I saw inside the .git folder that there is a "config" file - I tried adding:

[diff]
tool = bcompare


But this did not seem to work when I entered the command
git difftool
...

Answer

As mentioned in the comments, it is not possible to have repository configurations roll out to everybody who clones the repository. This applies to direct configurations stored in .git/config but also to things like hooks. Whenever you clone a repository, the default repository template is copied from /usr/local/git/share/git-core/templates and complemented with general configurations (e.g. the .git/config and general refs) that are created as part of the cloning process.

Since the configuration is always local to the repository, cloned repositories will also not copy over settings from the origin’s local configuration.

For hooks, the common solution to this problem is to have some setup script, either directly within the repository or as part of some other globally available tooling (e.g. Gerrit’s git-review) that sets up the local configuration when it’s first used.

For your diff/merge tool, you could provide a similar setup script that does this for your team members.

Note though, that tools are often very specific not only to the computer that it’s being used on (e.g. I could have installed my Beyond Compare into a different folder than you), but also very subjective. There may be people who are more comfortable with using tool X instead of the tool Y you configured as a default. So I would recommend to leave this up to the developer. Chances are, if they care, they already set up some tool globally anyway.

Comments