25

I'm syncing ~/.gitconfig and ~/.gitignore files in ubuntu and Mac by using dropbox and created symlink for it.

And excludesfile is declared like this.

[core]
        editor = /usr/bin/vim
        excludesfile = /Users/username/.gitignore

The problem is home directory differs by os, therefore I need multiple setting for excludesfile.

Is it possible to define multiple core.excludesfile?

1 Answer 1

30

You can only have a single core.excludesfile; the last setting is the one that's used. However, you don't need multiple files: git supports ~ as an abbreviation for your home directory.

[core]
    excludesfile = ~/.gitignore

In general, if you really needed to have multiple excludes files, the simplest solution would be to generate a single file that's the concatenation of the others, and update it whenever one of the files changes.

4
  • My .gitconfig is actually under version control by git. Unfortunately, git expands ~ to be the full path to $HOME and updates the .gitconfig itself with the absolute path. That behavior is fine, but then it shows up as an unstaged change, so I use git update-index --assume-unchanged .gitconfig to ignore the expansion (along with the rest of the file).
    – Dolph
    Oct 8, 2014 at 16:51
  • 2
    @Dolph status-norepro What did you do to cause ~ to be expanded? I get: git config --global core.excludesfile '~/.gitignore'; git config --global core.excludesfile~/.gitignore (git 1.7.9.5) Oct 8, 2014 at 17:22
  • 1
    @Dolph Most likely this was a shell expansion; after all, if you do git config --global core.excludesfile ~/.gitignore then what is actually run is git config --global core.excludesfile /path/to/home/.gitignore. Sep 23, 2016 at 3:07
  • 5
    @Gilles, note also that per git-scm, the file ~/.config/git/ignore if it exists is globally ignored automatically, with no global configuration necessary.
    – Asclepius
    Oct 3, 2016 at 22:54

You must log in to answer this question.

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