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.

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.