loading...

Repository-Specific Ignored Files in Git

hoelzro profile image Rob Hoelz ・1 min read

Originally published at hoelz.ro

Have you ever been working in a Git repository and wanted Git commands like git status to ignore certain files, but you didn't want to contaminate the project's .gitignore file with your specific ignore rules? Well, with .git/info/exclude, you can!

Let's say you want to ignore a file called notes. I do this a lot, because I don't like polluting the revision history when I make changes to notes I have about a project.

Instead of doing this:

  $ echo notes >> .gitignore

do this:

  $ echo notes >> .git/info/exclude

.git/info/exclude is never shared between repositories, so you can keep some files to yourself without the extra output from git status and friends.

You can also add ignore patterns specific to your computer using ~/.gitconfig; simply add the following (or something like it):

[core]
  excludesfile = /home/myuser/.gitignore

Now /home/myuser/.gitignore will also be consulted for ignore patterns!

Discussion

pic
Editor guide
Collapse
smichaelsen profile image
Sebastian Michaelsen

Your personal .gitignore should contain files/directories that are produced by your OS, IDE and personal tools.
In my opinion things like .idea, .DS_Store, Thumbs.db do not belong in a project's .gitignore but in personal ignore files.

Collapse
moopet profile image
Ben Sinclair

I agree, but the number of other developers on any random project who use badly-behaved OS or IDEs is often quite high. You could tell them to use a particular .gitignore configuration and double-check all their commits, or you could just include it all in the repo and forget about it.

Collapse
hoelzro profile image
Rob Hoelz Author

Definitely agree on this!

Collapse
shostarsson profile image
Rémi Lavedrine

I didn't know that one, that is interesting indeed.

Collapse
vlasales profile image
Vlastimil Pospichal

I have two git macros for edit these files: git ignore and git exclude.

Collapse
florimondmanca profile image
Florimond Manca

Great tip! Definitely useful instead of polluting the repo’s gitignore. The fact that you can define a global configuration applied to all repos is awesome. Too bad it’s not known more!

Collapse
moopet profile image
Ben Sinclair

How do you know it's not well-known? :P

Collapse
gabrielbhh profile image
Gabriel Ben Harosh

This is useful information, thank you.

Collapse
andy profile image
Andy Zhao (he/him)

Cool tip! Thanks for sharing. I've kept things in a separate folder for a long time, or just remember to not add it, which ends up taking more bandwidth than I'd like.

cc @maestromac

Collapse
maestromac profile image
Mac Siri

This is really awesome!

Collapse
zeddotes profile image
zeddotes

Thanks for the tip :)

Collapse
beyrem_makh profile image