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?

ironsand
  • 5,205

1 Answers1

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.

  • 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 08 '14 at 16:51
  • 2
    @Dolph [meta-tag: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) – Gilles 'SO- stop being evil' Oct 08 '14 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. – Resigned June 2023 Sep 23 '16 at 03: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 03 '16 at 22:54