Skip to content
Technical Documentation & Reference

.gitignore Guides & Reference

In-depth technical guides, syntax explanations, pattern mechanics, and troubleshooting workflows for Git ignore files.

.gitignore Guides & Reference

Workflows
5 min read readVerified Git 2.40+

How to Ignore a Directory in Git

Clear explanation of directory ignore rules: trailing slash behavior, root-relative folders, subdirectories, and keeping empty directories.

Frequently Asked Questions

Practical answers to common developer questions about .gitignore rules, caching, and repository configuration.

Why does Git still track a file after I added it to .gitignore?

.gitignore only stops Git from tracking newly added files. If a file was already committed, Git continues tracking it until you remove it from the index with 'git rm --cached <file>'.

How do I check which rule is ignoring a specific file?

Run 'git check-ignore -v <filepath>'. Git outputs the exact .gitignore file path and line number that matches the file.

Why does '!folder/file.txt' fail when 'folder/' is in .gitignore?

Git skips directory traversal when a parent directory is excluded. To whitelist a file inside an ignored folder, ignore folder contents with 'folder/*' and whitelist the target.

What is the difference between 'build' and 'build/' in .gitignore?

'build/' matches only directories. 'build' matches both directories and regular files named build.

How do I keep an empty directory in a Git repository?

Git tracks files, not directories. Create an empty file named .gitkeep inside the folder, ignore folder contents with 'folder/*', and whitelist '!folder/.gitkeep'.

Where should I ignore personal editor and OS files (like .DS_Store or .vscode)?

Use a global ignore file via 'git config --global core.excludesFile ~/.gitignore_global' so personal workstation artifacts do not clutter shared team repositories.