4

Me 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. We also know that we can include a file using git config --local include.path path-to-file, but that would require that everybody runs this command after cloning the repository which is not what we want.

2
  • Maybe you could put config under the template directory in every machine. The default template path varies on different systems. See git-scm.com/docs/git-init#_template_directory. Unless another template is specified, a newly initialized or cloned repository always has .git/config copied from the template. Commented Mar 25, 2020 at 11:52
  • Thanks for the template directory tip. It is another approach that we will consider alongside other solutions that we've thought that require more work on the machines than just git clone .... Commented Mar 25, 2020 at 12:01

1 Answer 1

1

git config has an include sections, and also includeIf sections (docs)

You could choose a convention on where the company's repositories should be cloned (e.g : in a specific /path/to/company ? a specific prefix in the projects' names ?), and set an includeIf section once on each workstation in the global config.


Another way could be to deploy a git-companyconfig script on each workstation, so that setting up the config in an existing repo would be a uniform call to git companyconfig,
and possibly a git-companyclone that would run git clone xx/project && cd project && git companyconfig
(obviously, I will let you choose better names for your custom git commands ...)

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.