You Should Know Git Exclude

Ignore local test files without updating .gitignore

·
·

I read an article today by Marijke titled Git exclude, a handy feature you might not know about, and I was pleasantly surprised to learn about it! You can (and should!) read the original article, but I like compressing information down to its barest essentials.

If you’ve used git ignore before, git exclude functions similarly, but there are two key differences:

  1. You can only have one exclude file.
  2. Git does not track the exclude file.

The file is located in your .git directory, at .git/info/exclude, but if it doesn’t exist you can create it. It is essentially a local .gitignore, letting you ignore temporary test files or personal scripts that shouldn’t be committed to the repo, without updating the git ignore file.

For the past couple days I had a test page on my website that I didn’t want to commit to the repo, but I didn’t want to add to my .gitignore either, so it was just awkwardly left unstaged. But with git exclude I can have my cake and eat it too!

signature that says "Chai"

Likes

bscit

Wow, how have I never heard about this feature before????

Lucia

That's so helpful, thank you for sharing that! There are a few editor plugins that I use for Godot (script-ide, godot-vim) that have always been annoying to deal with. On my own projects its not too bad, but adding it to a .gitignore of someone elses project doesn't work so well.