Modify git config file globally

git github gitlab git-commit git-config

633 просмотра

3 ответа

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?

Автор: Dheeraj Manthangode Источник Размещён: 22.09.2019 12:05

Ответы (3)

1 плюс


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.

Автор: ElpieKay Размещён: 21.06.2017 12:35

0 плюса

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
Автор: Antwane Размещён: 21.06.2017 10:22

0 плюса

I think you can create a 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!!!

Автор: An Huy Размещён: 21.06.2017 10:23
Вопросы из категории :