.gitignore Isn't the Only Way to Ignore Files in Git

Hacker News Top Tools

Summary

Explains three levels of git ignore files: per-repo checked-in (.gitignore), per-repo not checked-in (.git/info/exclude), and global machine-level (~/.config/git/ignore), plus how to check which file is ignoring a specific file.

No content available
Original Article
View Cached Full Text

Cached at: 06/18/26, 02:49 PM

# .gitignore Isn’t the Only Way To Ignore Files in Git Source: [https://nelson.cloud/.gitignore-isnt-the-only-way-to-ignore-files-in-git/](https://nelson.cloud/.gitignore-isnt-the-only-way-to-ignore-files-in-git/) I’ve been using Git for so long and I just realized you can ignore files at three different levels and not just with`\.gitignore`\. The three files you can use to ignore files are: - `\.gitignore` - `\.git/info/exclude` - `~/\.config/git/ignore` `\.gitignore`is the usual file where you write files you want to ignore\. It’s checked into Git along with the rest of the code\. Whatever files you add to it will not get taken into account when running`git`commands\. ## [\.git/info/exclude](https://nelson.cloud/.gitignore-isnt-the-only-way-to-ignore-files-in-git/#gitinfoexclude) The`exclude`file lives in the`\.git`directory of every Git repository but changes to it are not checked into Git\. It usually has a few comment lines on a fresh Git repository\. This file is useful for ignoring things on a per\-repo basis\. For example, you may have a personal`notes\.txt`file in a repository that you don’t want to check into git but you also don’t want to add to`\.gitignore`because it’s unique to your workflow\. In that case you would add`notes\.txt`to`\.git/info/exclude`\. ## [~/\.config/git/ignore](https://nelson.cloud/.gitignore-isnt-the-only-way-to-ignore-files-in-git/#configgitignore) The`ignore`file lives in your machine’s home directory in`~/\.config/git/ignore`\. Whatever filenames are added to this file are ignored globally at a machine\-level\. This file is not checked into Git and isn’t associated with any particular repository\. It’s a great place to add files that you want to ignore in every git repository on your computer\. For example, if you’re on macOS, adding`\.DS\_Store`here would be ideal\. You can customize the global ignore file to be a different file\. For example, if you want your global git ignore file to be`\.gitignore\_global`you would run the command: Shell ``` git config --global core.excludesFile ~/.gitignore_global ``` And if you ever want to return to the default setting, run: Shell ``` git config --global --unset core.excludesFile ``` ## [Checking Which File Is Ignoring a Specific File](https://nelson.cloud/.gitignore-isnt-the-only-way-to-ignore-files-in-git/#checking-which-file-is-ignoring-a-specific-file) When adding filenames to any of these, you can use this command to check how a filename is being ignored\. For example, if you want to check how`\.DS\_Store`is being ignored, run`git check\-ignore \-v \.DS\_Store`in any Git repository\. Here is the output when the repository’s`\.gitignore`is ignoring`\.DS\_Store`: Console ``` $ git check-ignore -v .DS_Store .gitignore:1:.DS_Store .DS_Store ``` Here is the output when the repository’s`\.git/info/exclude`is ignoring`\.DS\_Store`: Console ``` $ git check-ignore -v .DS_Store .git/info/exclude:7:.DS_Store .DS_Store ``` Here is the output when the global`~/\.config/git/ignore`file is ignoring`\.DS\_Store`: Console ``` $ git check-ignore -v .DS_Store /Users/nelson/.config/git/ignore:2:.DS_Store .DS_Store ``` And here is the output when a custom global ignore file`\.gitignore\_global`is ignoring`\.DS\_Store`: Console ``` $ git check-ignore -v .DS_Store /Users/nelson/.gitignore_global:1:.DS_Store .DS_Store ``` If there is nothing ignoring a file, the`git check\-ignore \-v`command produces no output\.

Similar Articles

Why don't people use git properly?

Lobsters Hottest

An essay exploring why many developers struggle to use git properly, covering common mistakes like panic over merge conflicts, huge commits, and poor branching practices, and examining the root causes.

What is Git made of? (2022)

Lobsters Hottest

An in-depth tutorial explaining the internal structure of Git, including objects, hashes, and how Git stores data, with examples in Go and shell commands.

Git Is Not Fine

Lobsters Hottest

The article critiques Git, arguing that it is not as fine as commonly perceived, and links to a discussion on Lobste.rs.