Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OS (or hostname) specific sections of gitconfig

Tags:

git

I have a gitconfig file that I share between machines since, for the most part, I want to use the same options on all of my machines. However, there are some things that are specific to the system (credential helper, difftool, etc.).

Is there any way to have a system specific part of the gitconfig file (like I can in my bashrc or vimrc files)?

like image 834
Wesley Bland Avatar asked Sep 07 '25 22:09

Wesley Bland


1 Answers

Yes, git has two user-specific configuration files: $XDG_CONFIG_HOME/git/config and ~/.gitconfig. The git-config man page explains $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.

So copy your generic config into $XDG_CONFIG_HOME/git/config and put your system specific overrides into ~/.gitconfig. If you don't have a XDG_CONFIG_HOME environment variable, you should probably set it to $HOME.

like image 172
Schwern Avatar answered Sep 09 '25 23:09

Schwern