Repository-Specific Ignored Files in Git
Rob Hoelz

Rob Hoelz @hoelzro

About: Hi, I'm Rob! I like programming, gaming, languages, and birds. Opinions shared are my own.

Location:
Wisconsin
Joined:
Apr 4, 2017

Repository-Specific Ignored Files in Git

Publish Date: Aug 9 '18
88 12

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
Enter fullscreen mode Exit fullscreen mode

do this:

  $ echo notes >> .git/info/exclude
Enter fullscreen mode Exit fullscreen mode

.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
Enter fullscreen mode Exit fullscreen mode

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

Comments 12 total

  • zeddotes
    zeddotesAug 9, 2018

    Thanks for the tip :)

  • Rémi Lavedrine
    Rémi LavedrineAug 9, 2018

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

  • Andy Zhao (he/him)
    Andy Zhao (he/him)Aug 9, 2018

    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

  • beyrem Makhlouf
    beyrem MakhloufAug 9, 2018

    Awesome

  • Sebastian Michaelsen
    Sebastian MichaelsenAug 10, 2018

    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.

    • Rob Hoelz
      Rob HoelzAug 10, 2018

      Definitely agree on this!

    • Ben Sinclair
      Ben SinclairDec 7, 2018

      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.

  • Florimond Manca
    Florimond MancaAug 10, 2018

    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!

    • Ben Sinclair
      Ben SinclairDec 7, 2018

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

  • Vlastimil Pospichal
    Vlastimil PospichalAug 11, 2018

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

  • Gabriel Ben Harosh
    Gabriel Ben HaroshAug 17, 2018

    This is useful information, thank you.

  • Mac Siri
    Mac SiriSep 4, 2018

    This is really awesome!

Add comment