Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to set a Git config for all users in a system?

Tags:

git

Suppose I need to set a git alias that every user in the system has to use. Instead of asking each user to add this config to their $HOME/.gitconfig, is it possible to declare this once globally for all users?

like image 434
thameera Avatar asked Mar 11 '13 09:03

thameera


1 Answers

The docs say:

If not set explicitly with --file, there are four files where git config will search for configuration options:

$GIT_DIR/config
Repository specific configuration file.

~/.gitconfig
User-specific configuration file. Also called "global" configuration file.

$XDG_CONFIG_HOME/git/config
Second user-specific configuration file. If $XDG_CONFIG_HOME is not set or empty, $HOME/.config/git/config will be used. Any single-valued variable set in this file will be overwritten by whatever is in ~/.gitconfig. It is a good idea not to create this file if you sometimes use older versions of Git, as support for this file was added fairly recently.

$(prefix)/etc/gitconfig
System-wide configuration file.

So:

  • /etc/gitconfig is global
  • ~/.gitconfig and $XDG_CONFIG_HOME/git/config are per user
  • $GIT_DIR/config is per repo

In order to set a system wide option, do git config --add --system <OPTION>

like image 157
eckes Avatar answered Oct 01 '22 14:10

eckes