What is a .gitignore file?
A .gitignore file is a plain text file placed in your Git repository root. It specifies intentionally untracked patterns and files that Git should ignore, preventing build outputs, local secrets, package directories, and temporary system files from being committed to source control.
Where should I put .gitignore?
Place your .gitignore file in the root directory of your project (e.g., /my-project/.gitignore). When placed in the root, its pattern rules apply recursively to all files and subdirectories across the entire repository. You can also place additional .gitignore files in subdirectories if specific rules apply only to those paths.
Can I combine multiple .gitignore templates?
Yes. Modern projects almost always combine multiple technologies (e.g., Python + React + Docker + macOS + VS Code). DotGitIgnore allows you to select as many technology templates as you need, automatically resolving overlaps and deduplicating identical rules into a single clean file.
How do I ignore a directory?
To ignore an entire directory and all of its contents, append a trailing forward slash to the directory name in your .gitignore file (e.g., node_modules/ or build/). A pattern without a trailing slash matches both files and directories with that name, whereas a trailing slash restricts the match strictly to directories. Read the Ignoring Directories Guide.
How do I stop tracking a file that is already committed?
Adding a file to .gitignore does not remove it from Git if it was already tracked in previous commits. To stop tracking an existing file without deleting it from your local disk, run 'git rm --cached <file>' (or 'git rm -r --cached <directory>/' for folders), and then commit the change. Read the Ignoring Tracked Files Guide.
Can I edit the generated .gitignore?
Yes. The output generated by DotGitIgnore is standard Git configuration text. You can freely add project-specific paths, customize environment-specific secrets, add comments, or toggle individual rules directly within the generator or in your text editor after downloading.
How to use .gitignore in Git?
Create a file named .gitignore in your repository root, add relative file or directory pattern rules you want Git to exclude (such as dist/, .env, or *.log), and commit the .gitignore file to Git with 'git add .gitignore && git commit -m "Add .gitignore"'. From that point on, Git will ignore newly created untracked files matching those rules.
How does gitignore work?
During working tree inspections (such as 'git status' or 'git add .'), Git checks untracked files against pattern rules defined in your .gitignore hierarchy. If an untracked path matches an ignore pattern and is not negated by a subsequent '!' pattern, Git skips indexing that file and omits it from untracked file listings.
What does gitignore do?
A .gitignore file instructs Git which untracked files and directories to exclude from version control. It prevents temporary caches, compiled artifacts, third-party packages, operating system metadata (.DS_Store), and secret credentials from cluttering commits or being pushed to remote repositories. Browse verified technology templates.
Should .gitignore be in Git?
Yes. In almost all circumstances, .gitignore should be committed to your repository so that ignore rules are shared consistently across all team members and CI/CD pipelines. For personal files unique to your local workstation (like local IDE preferences), use .git/info/exclude or a global gitignore instead.
Why is .gitignore not ignoring files?
The most common reason is that the file is already being tracked by Git. .gitignore only prevents untracked files from being staged; it never untracks files that were previously committed. To fix this, untrack the file using 'git rm --cached <file>' and commit the change. Other common causes include pattern syntax errors or leading slashes that restrict matching to the wrong directory level.
What happens if you gitignore .gitignore?
If .gitignore has already been committed to the repository, adding .gitignore to itself has no effect because Git already tracks it. If you add .gitignore to itself before ever staging it, Git will ignore the .gitignore file, preventing you from committing and sharing ignore rules with team members. In practice, you should never ignore .gitignore.
How do I know if .gitignore is working?
You can test whether a file is ignored using the command 'git check-ignore -v <path>'. If the path is ignored, Git outputs the matching .gitignore file path, line number, and pattern. You can also run 'git status --ignored' to display all currently ignored files in your working directory.
How to correctly use .gitignore?
To correctly use .gitignore, create it before making your initial project commit, group rules by logical category (dependencies, build outputs, local secrets), commit .gitignore to source control, and keep machine-specific tools in your personal global gitignore. Using DotGitIgnore helps ensure you start with clean, deduplicated rules tailored to your exact stack.
What should I put in a .gitignore file?
Include build outputs (dist/, build/), dependency directories (node_modules/, vendor/), environment credentials (.env*), compiled binaries (*.class, *.o), and runtime logs. Never ignore source code, configuration templates (such as .env.example), or package lockfiles (package-lock.json, Cargo.lock) required for reproducible builds. Explore Node.js template rules.
Can I have multiple .gitignore files in a repository?
Yes. Git supports multiple .gitignore files across your directory hierarchy. Patterns in a subdirectory's .gitignore file apply only to that directory and its children, taking precedence over root patterns for matching paths. This is especially useful in monorepos housing multiple languages or microservices.
How do I ignore a specific file in Git?
To ignore a specific file anywhere in the repository, add its filename to .gitignore (e.g., secret.txt). To restrict the rule strictly to the repository root, prefix it with a forward slash (e.g., /secret.txt). To ignore a specific nested file, specify its relative path from the root (e.g., config/credentials.json).
How do I ignore environment variables and .env files?
Add .env and local variants (such as .env.local and .env.*.local) to .gitignore to prevent leaking API keys and database credentials. Always commit a sanitized .env.example file containing placeholder values so collaborators know which environment variables are required without exposing secrets.
What is the difference between .gitignore and .git/info/exclude?
.gitignore is tracked in version control and shared across all repository contributors, making it ideal for project-wide rules (such as build output and dependencies). In contrast, .git/info/exclude is a local configuration file stored inside .git/ that is never committed or pushed, making it ideal for private, machine-specific ignore patterns.
What does the exclamation mark (!) do in .gitignore?
An exclamation mark (!) negates a pattern to re-include a file that was matched by an earlier ignore rule (e.g., *.log followed by !important.log). Note that Git cannot re-include a file if its parent directory is already excluded, because Git does not traverse inside ignored directories. Read the full .gitignore Syntax Guide.
How do I force Git to track an ignored file?
You can force Git to stage a file that matches an ignore pattern by passing the -f (or --force) flag: 'git add -f path/to/file'. Once staged and committed, the file remains tracked by Git even if it matches a .gitignore rule, until it is explicitly untracked with 'git rm --cached'.