Tech News
← Back to articles

Git's Magic Files

read original related products more articles

A follow-up to my post on extending git functionality. Git looks for several special files in your repository that control its behavior. These aren’t configuration files in .git/ , they’re committed files that travel with your code and affect how git treats your files.

If you’re building a tool that works with git repositories, like git-pkgs, you’ll want to ensure you respect these configs.

.gitignore

Patterns of files git should never track. One pattern per line, supports wildcards and directory markers.

node_modules/ *.log .env dist/

Git checks multiple ignore files in order: .gitignore in each directory, .git/info/exclude for local-only ignores, and the global ignore file at ~/.config/git/ignore or wherever core.excludesFile points. Global ignores are good for OS-specific files like .DS_Store or Thumbs.db that shouldn’t clutter every project’s .gitignore .

The pattern matching supports wildcards ( *.log ), directory markers ( dist/ ), negation ( !important.log ), and character ranges. The ** pattern matches nested directories.

GitHub, GitLab, and Gitea all respect .gitignore and won’t show ignored files in the web UI. Package managers often ship with their own ignore patterns ( node_modules/ , vendor/ , target/ ) that you’re expected to add to your ignore file.

See the gitignore docs for the full pattern syntax. GitHub maintains a collection of .gitignore templates for different languages and frameworks.

.gitattributes

... continue reading