Ignoring Files with .gitignore
.gitignore, ignore patterns, node_modules, build artifacts, environment variables, .env files
Ignoring Files with .gitignore
Not every file in your project should be tracked by Git. Build artifacts, dependency folders, log files, and sensitive configuration should all be excluded. The .gitignore file tells Git which files and directories to ignore.
Creating a .gitignore File
Create a file named .gitignore in the root of your repository. Add patterns for files and folders you want Git to ignore:
# Node.js dependencies
node_modules/
# Build output
dist/
build/
# Environment variables
.env
.env.local
# OS-generated files
.DS_Store
Thumbs.db
# Log files
*.logPatterns ending with / match directories. Patterns starting with ! are negations (include a file that a broader pattern would ignore). The * wildcard matches any sequence of characters within a filename.
Global .gitignore
You can set a global ignore file for system-level files that should be ignored in every project:
git config --global core.excludesfile ~/.gitignore_globalAdd entries like .DS_Store and *.swp to this file so you never accidentally commit OS or editor artifacts.
Untracking Already-Tracked Files
If you added a file to .gitignore after already committing it, Git will still track it. Remove it from tracking without deleting it from disk:
git rm --cached filename.txtThen commit the change. The file will no longer appear in future commits.
