Script Valley
Developer Environment Setup (WSL, Terminal, VS Code)
Git Workflows and Developer Best PracticesLesson 6.4

How to use .gitignore to exclude files from version control

.gitignore syntax, negation patterns, global gitignore, ignoring already-tracked files, gitignore.io, common patterns for Node.js and Python, git rm --cached

Using .gitignore Effectively

.gitignore filter flow diagram

A .gitignore file tells Git which files and directories to exclude from tracking. Every project needs one before the first commit.

Syntax

node_modules/
*.log
.env
dist/
!dist/.gitkeep     # negation: track this one file inside dist/

Common .gitignore for Node.js

node_modules/
dist/
.env
.env.local
*.log
.DS_Store
coverage/

Generate with gitignore.io

curl https://www.toptal.com/developers/gitignore/api/node,linux,visualstudiocode \
  -o .gitignore

Untracking an already-committed file

git rm --cached .env
echo ".env" >> .gitignore
git commit -m "chore: remove .env from tracking"

Global gitignore

git config --global core.excludesfile ~/.gitignore_global
echo ".DS_Store" >> ~/.gitignore_global
echo "*.swp" >> ~/.gitignore_global

Global gitignore keeps OS-specific noise out of every repo without cluttering the project own .gitignore.

Up next

How to use Git stash, rebase, and cherry-pick for advanced workflows

Sign in to track progress