Git config allows to include files like:
[include]
path = /path/to/file
My question is: can I use environment variable to specify the file name? Like path = /etc/git/$MYVAR/gitconfig.
Git config allows to include files like:
[include]
path = /path/to/file
My question is: can I use environment variable to specify the file name? Like path = /etc/git/$MYVAR/gitconfig.
Environment variables are not resolved when Git is reading a config file.
The only one which might be expanded is ~:
If the pattern starts with
~/,~will be substituted with the content of the environment variableHOME.
Generating the config you need (through .bashrc for instance) is one workaround.
No that's not possible. Git doesn't evaluate environmental variables when processing config.
There is conditional include directive [includeIf] that allows to include different configs based on where repository is (gitdir:) or which branch is checked out (onbranch:). For example following snippet:
[includeIf "gitdir:~/repos/work"]
path = ~/repos/work/.gitconfig
in your .gitconfig will make Git only include ~/repos/work/.gitconfig for repos under ~/repos/work - e.g. ~/repos/work/proj1 but not ~/repos/fun/project2. See more info on https://git-scm.com/docs/git-config#_includes
This is available since Git version 2.13