52
$ cat ~/.gitconfig
[core]
        editor = vim
        excludefiles = /home/augustin/.gitignore
$ cat ~/.gitignore
toto
$ mkdir git_test
$ cd git_test/
$ git init
$ touch toto
$ git status

# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       toto
nothing added to commit but untracked files present (use "git add" to track)
$ git --version
git version 1.6.3.3

Why isn't toto being ignored?

Other settings in ~/.gitconfig are taken into account (colors, editor).

augustin
  • 14,373
  • 13
  • 66
  • 79

2 Answers2

114

git config --global core.excludesfile ~/.gitignore

sakisk
  • 1,807
  • 1
  • 24
  • 30
  • 9
    I had checked and double checked for any typo, but my original problem boiled down to a missing 's' in the variable setting name. I realized the problem after checking the config file after having applied your solution. Thanks. – augustin Mar 11 '11 at 09:58
  • I noticed that if you use ~/ or $HOME/ in your command, it expands to /Users/USER/. Wonder if this is what's causing my issues too. – Kevin Suttle Dec 31 '13 at 21:33
  • 1
    @KevinSuttle that looks like a configuration of the system that you use. Are home directories indeed under /Users or under /home ? Git knows nothing about $HOME or ~, they are expanded by the shell. – sakisk Jan 01 '14 at 13:34
  • Slight followup ... I have my global ignores in a file called ~/.gitingnore_global (so I'm not confused with my repo-local .gitignore definitions). Thus, the command changes slightly to: "git config --global core.excludesfile ~/.gitignore_global" – DevByStarlight Apr 03 '14 at 17:00
  • 3
    WARNING : DO NOT USE A RELATIVE PATH, use an absolute path like the one of this answer. – Mmmh mmh Aug 27 '14 at 08:34
  • 1
    I've copy and pasted and this still isn't working for me. I checked `~/.gitconfig` and saw an entry for `/home/username/.gitconfig` under `excludesFile` under `[core]`. I went into the file `nano /home/username/.gitconfig` and put in a fully qualified path to a file in my source tree. I saved the file and typed `git status` and the file is still detected for changes. – fIwJlxSzApHEZIl Oct 02 '18 at 15:52
0

You may find this question when trying to ignore a specific file that you may not want to include in an open source project, but one that fits a pretty common pattern for you and you may want to include it in your other projects. For example, you may want to reflexively run tests with the same command regardless of the language, and you may keep the fiddly details of this in a local file that you usually want checked in on private projects, but not on projects you're helping out with.

Say the file is called test there are two solutions. First, your bash alias can look something like this:

./test || ./.test

And you can add .test in your global git ignore.

Or you can follow the advice given here on how to create a local gitignore; but note that it will override your global git ignore, so you'll need to include whatever is in your global git ignore there too.

zachaysan
  • 1,726
  • 16
  • 32