11

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?

15

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 8 '14 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) – Gilles 'SO- stop being evil' Oct 8 '14 at 17:22
  • @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. – Radon Rosborough Sep 23 '16 at 3:07
  • @Gilles, note also that per git-scm, the file ~/.config/git/ignore if it exists is globally ignored automatically, with no global configuration necessary. – Acumenus Oct 3 '16 at 22:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.