1

I added a gitconfig to my dotfiles. To keep things tidy, a symlink at ~/.gitconfig points to the real file, which lives elsewhere.

I want to have a section like:

[include]
    path = other-file.txt

in my gitconfig. But this doesn't work because it tries to include ~/other-file.txt (relative to symlink) which doesn't exist. Instead I have to use:

[include]
    path = /absolute/path/to/other-file.txt

But if I ever move my dotfiles directory, now this include will break. Is there a way to make the relative path work?

1 Answer 1

1

No, there isn't a way to get Git to resolve symlinks before computing a relative path. The documentation specifically says that it's relative to the file being loaded, which is ~/.gitconfig.

However, Git supports multiple per-user files. There's $HOME/.gitconfig and $XDG_CONFIG_HOME/git/config. In the latter case, if $XDG_CONFIG_HOME is not set, it defaults to ~/.config. As a result, you can store your Git configuration in ~/.config/git/config and then also have ~/.config/git/other-file.txt, which should work correctly.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .