Not all files inside your project directory belong in version control. Build outputs, temporary OS files, package dependencies, and sensitive credentials must never be committed. Git uses the .gitignore configuration file to ignore these files automatically.
In a professional software project, the following categories must be ignored:
.env, secrets.json, .pem SSH keys, AWS credentials. (Committing these leads to critical security breaches!)node_modules/, venv/, vendor/, target/. (These can be regenerated via package managers like npm install or pip install).dist/, build/, .next/, *.pyc, *.exe, *.dll..DS_Store (macOS), Thumbs.db (Windows), .idea/, .vscode/settings.json.*.log, npm-debug.log*, *.tmp..gitignore FileA .gitignore file is a plain text file placed at the root of your repository. Each line specifies a pattern:
| Pattern Syntax | Matches | Example |
|---|---|---|
filename.ext | Matches filename.ext in any directory | .env ignores all .env files |
/filename.ext | Matches only in the root directory where .gitignore lives | /TODO.txt ignores root TODO.txt only |
directory/ | Matches the directory and all contents recursively | build/ ignores build folder |
* | Matches zero or more arbitrary characters | *.pdf ignores all PDF files |
** | Matches directories across leading or nested paths | **/logs/*.txt |
! | Negation rule (do not ignore this file) | !release.log |
.gitignore will NOT stop Git from tracking it! .gitignore only applies to untracked files.To remove a file from Git's tracking without deleting the file from your local disk, use git rm --cached:
.gitignore for Developer-Specific FilesOperating system junk files like macOS .DS_Store or Windows Thumbs.db shouldn't clutter every team project's repo .gitignore. You can configure a personal global gitignore:
.gitignore file in a Git project?.env) NEVER be committed to Git?*.log match inside a .gitignore file?secrets.json to .gitignore, but it was already committed last week, what happens?Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
Test your understanding of this lesson with 5 questions. Each question has one correct answer.
Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.