Dheeraj Manthangode
Dheeraj Manthangode

Reputation: 13

Modify git config file globally

We would like to change the git config file globally, such that new file get downloaded from git repo on every git clone. Is there a way to do so? Any user who does git clone of the project should get this customized git config file in ./git/config file instead of standard one?

Upvotes: 0

Views: 2857

Answers (3)

ElpieKay
ElpieKay

Reputation: 30958

I don't think it's a good idea for git-clone to do this job. It's unsafe and unreasonable to modify a local existing file or override the local config without the user's awareness or permission.

I don't know why you'd like to do so but I think you can do it through other means. For your team members, you could tell them the rules they must obey during the development. For a random user who may clone your project and contribute, you could write down the rules in README or project introduction. Users should be allowed to do whatever they'd like to in their local repositories. But when their commits are to be merged or applied into the blessed repository, you could set up barriers to those unsatisfactory commits.

For example, if you don't want files that contain dos style line endings, you could detect them in a pre-receive hook, prevent the push, and then respond in the error message to explain why the push has failed and suggest what to do to fix the error. Making a specific git-config can be included in the suggestion.

Upvotes: 1

An Huy
An Huy

Reputation: 442

I think you can create a config_symlink.sh file: It will create a symlink from your config file which has been push to git. And link that file to ./.git/config

ln -s ./config ./.git/config

Then push two files.

Good luck!!!

Upvotes: 0

Antwane
Antwane

Reputation: 22688

As far as I know, it's not possible to force modification in global Git config for users when they clone your repository. It would cause serious security issues.

What if you decide to modify the users "signingkey" or modify the path to an executable (mergetool, difftool, etc.) ?

Instead, you could write a script modifying the config you want to update and ask users to execute this script.

You can use the following commands to update git configs:

git config --global <key> <value>  # modify global .gitconfig
git config <key> <value>           # modify current repository config

Upvotes: 0

Related Questions