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
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 .gitignoreUntracking 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_globalGlobal gitignore keeps OS-specific noise out of every repo without cluttering the project own .gitignore.
