Sharing git configuration file across different computers working on the same repository

I and my colleagues develop software using git for version control. However, it is pretty difficult that we all use the same --no-ff policy across different types of merges. We know that this can be configured in .git/config for each repo locally or in ~/.gitconfig for all repositories. And we have seen that this configuration file is very powerful allowing use the set different default policies for different branches. However, this file (.git/config) is not something that is pushed to the repository. Therefore, we cannot share these defaults across different working computers by just cloning the repository. Is there a way that this config can be automatically set in the repository? We want this configuration file to work similarly to .gitignore where everybody working with the repo containing the .gitignore has the same ignore policy. I have tested adding a .gitconfig with the desired configuration in the root of the git repository (next to .gitignore) and it did not work.

Is there a way that this config can be automatically set in the repository?

@apalomer - Great question! There’s not a specific “built-in” feature in Git that would allow you to do this per repository. However, one approach you could take is creating a file that executes each of the commands for setting the respective Git configuration. Then, your project could include a “setup” script that also executes that Git configuration before running the project locally. Granted, there are possibly other approaches that others have to share and it’s more a matter of preference than there being “one right way” to do it.

I hope this helps!