views:

756

answers:

2

Can I ignore files locally without polluting the global git config for everyone else? I have untracked files that are spam in my git status but I don't want to commit git config changes for every single little random untracked file I have in my local branches.

+6  A: 

gitignore:

Patterns which are specific to a particular repository but which do not need to be shared with other related repositories (e.g., auxiliary files that live inside the repository but are specific to one user's workflow) should go into the $GIT_DIR/info/exclude file.

The .git/info/exclude file has the same format as any .gitignore file. You can also set core.excludesfile to the name of a file containing global patterns.

Note on $GIT_DIR: This is a notation used all over the git manual simply to indicate the path to the git repository. If the environment variable is set, then it will override the location of whichever repo you're in, which probably isn't what you want.

jleedev
What's $GIT_DIR, I can set that to whatever I want in my .bash_profile? I don't seem to have a default value for it.
apphacker
If GIT_DIR is undefined it's just the path to the .git repository.
jleedev
So it's ok for me to set GIT_DIR to ~/.git in my .bash_profile? Thanks.
apphacker
apphacker: I doubt that's what you want to do. That makes any git command to refer to the repository stored in ~/.git. GIT_DIR in this answer is a placeholder referring to the directory your repository's stored in.
Jefromi
+5  A: 

You have several options:

  • Leave a dirty (or uncommitted) .gitignore file in your working dir (or apply it automatically using topgit or some other such patch tool).
  • Put the excludes in your $GIT_DIR/info/exclude file, if this is specific to one tree.
  • Run git config --global core.excludesfile ~/.gitignore and add patterns to your ~/.gitignore. This option applies if you want to ignore certain patterns across all trees. I use this for .pyc and .pyo files, for example.

Also, make sure you are using patterns and not explicitly enumerating files, when applicable.

Emil
I think you need `git config --global` to set the option globally.
jleedev
Indeed, thanks!
Emil