1

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.

Michael
  • 1,014
  • 2
  • 15
  • 26

2 Answers2

1

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 variable HOME.

Generating the config you need (through .bashrc for instance) is one workaround.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

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

blami
  • 6,588
  • 2
  • 23
  • 31