Frequently Asked Questions
What is a .gitignore file and why do I need one?▼
A .gitignore file tells Git which files and directories to ignore in a project. It prevents generated files, dependencies, build artifacts, IDE settings, and sensitive data (like .env files with API keys) from being tracked in version control. Every project should have one to keep the repository clean and avoid committing unnecessary or secret files.
Where should I place the .gitignore file?▼
Place the .gitignore file in the root directory of your Git repository. Git applies the rules relative to the location of the .gitignore file. You can also have .gitignore files in subdirectories for folder-specific rules. A global .gitignore (~/.gitignore_global) can be configured for patterns you want ignored across all repositories on your machine, like OS files (.DS_Store) and editor settings.
How do I ignore files that are already tracked by Git?▼
Adding a pattern to .gitignore only prevents untracked files from being added. If a file is already tracked, you must first remove it from the index with git rm --cached filename (keeps the local file) and then commit. For directories, use git rm -r --cached directoryname. After that, the .gitignore pattern will take effect.