HN
Today

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

This article illuminates Git's lesser-known file exclusion mechanisms beyond .gitignore, detailing .git/info/exclude for repository-specific and ~/.config/git/ignore for global user-level ignores. It also introduces the diagnostic git check-ignore -v command. Hackers appreciate uncovering these powerful, often overlooked features in widely-used tools, sparking discussion on best practices for managing local development environments.

136
Score
34
Comments
#12
Highest Rank
29h
on Front Page
First Seen
Jun 18, 1:00 PM
Last Seen
Jun 19, 5:00 PM
Rank Over Time
1812191816182120211918181816161617202219201817172121191722

The Lowdown

The article reveals that Git offers more than just the ubiquitous .gitignore for managing file exclusions, detailing three distinct layers of ignoring files. This hierarchy allows for flexible control over what Git tracks, from project-wide rules to personal, machine-specific configurations.

  • .gitignore: The standard, version-controlled file for repository-specific exclusions, shared among all collaborators.
  • .git/info/exclude: A local-only file within a repository's .git directory, ideal for personal exclusions that shouldn't be committed, such as local notes or temporary build artifacts.
  • ~/.config/git/ignore (or custom global file): A user-wide configuration located in the home directory, perfect for ignoring operating system junk (e.g., .DS_Store on macOS) or IDE-specific files across all repositories on a machine.
  • git check-ignore -v: A valuable command to pinpoint which specific ignore file and rule is causing a given file to be ignored, aiding in debugging.

By understanding these various ignore methods, developers can better tailor their Git workflow to keep repositories clean and focused on shared code, while accommodating personal preferences and local environment quirks.

The Gossip

Exclusion Education & Elation

Many commenters expressed delight and surprise at discovering the `.git/info/exclude` and global ignore files, particularly for keeping personal development files (like IDE settings, OS files, or local scripts) out of shared `.gitignore`s. This often leads to advice on standardizing how teams handle such files versus individual preferences.

Global vs. Local Governance

The discussion often veered into the nuances of Git's "global" configuration (meaning per-user) versus "system" (machine-wide), and best practices for managing dotfiles. Commenters debated whether to use the `~/.config/git/ignore` path directly or a custom global file, and the benefits of version controlling one's `~/.config` directory.

Alternative Approaches & Anecdotes

Users shared various personal strategies for file exclusion, such as creating special "attic" or ".local" directories within projects that are universally ignored. There was some debate over whether these alternative methods might lead to confusion or "sadness" compared to the standard `.gitignore`.

Git's Perceived Puzzles & Praises

As is common with Git topics, the comments included both praise for Git's power and flexibility, and observations on its perceived complexity. Some felt the article simply restated existing documentation, while others appreciated the concise summary and the inclusion of `git check-ignore -v`.