I have a shell variable which points to the directory where all my configuration files are located. Let’s assume the variable is created with export RC=$HOME/rc. I have a global ignore file in the configuration directory: ~/rc/globalgitignore.
My Question is, how can I expand the RC variable in my .gitconfig file?
I already tried the following:
-
excludesfile = $RC/globalgitignore -
excludesfile = !$RC/globalgitignore -
excludesfile = !echo $RC/globalgitignore -
excludesfile = !$(echo $RC/globalgitignore)
None of these solutions work.
The only way this works if I enter the full path: excludesfile = ~/rc/globalgitignore, but then I have to change the path if move my rc directory to a different location.
You can’t. git-config(1) does not support environment variable expansion, but only limited type conversion and path expansion:
The documentation for
--pathstates:The term “expansion” does not appear in any different context in
git-config(1). So how did you even get the idea that it should, given that no such feature is documented anywhere?In order to expand environment variables you have to pre-process the Git config file yourself, i.e. by creating a template file, and expand variables with a script before copying the file to your
$HOMEdirectory.If it’s about dotfile management, then do, what all people do: Put them in a directory, and add symlinks to this directory from your
$HOME.