Excluding Non-Essential Cargo
Not everything belongs in version control. Build artifacts, logs, secrets, and temporary files should stay out. The .gitignore file tells Git what to ignore.
Creating a .gitignore File
Create a file named .gitignore in your repository root:
touch .gitignore
Common Patterns
# Dependencies
node_modules/
venv/
__pycache__/
# Build outputs
dist/
build/
*.exe
*.dll
# Logs
*.log
logs/
# Environment variables
.env
.env.local
# IDE files
.vscode/
.idea/
*.swp
# OS files
.DS_Store
Thumbs.db
# Temporary files
*.tmp
temp/
Pattern Rules
#: Comments*: Wildcard (matches any characters)**: Matches across directories recursively!: Negation (don't ignore this)/: Directory separator
Examples
*.log # Ignore all .log files
build/ # Ignore build directory
!important.log # But track this one
**/temp # Ignore temp in any subdirectory
/*.txt # Ignore .txt files in root only
Language-Specific Templates
GitHub provides .gitignore templates for many languages at github.com/github/gitignore.
Global Ignore
Ignore files across all repositories:
git config --global core.excludesfile ~/.gitignore_global
When to Use .gitignore
Ignore:
- Generated files (build outputs)
- Dependencies (installed packages)
- Secrets (API keys, passwords)
- Personal IDE settings
- Log files
- Temporary files
Don't ignore:
- Source code
- Configuration templates
- Documentation
- Test files
Already Tracked Files
If you add a file to .gitignore after Git is already tracking it:
git rm --cached filename
This stops tracking it in Git but keeps the local file.
Checking Ignore Status
git status --ignored # Show ignored files
git check-ignore -v filename # Why is this ignored?
Common Mistake: Committing Secrets
Never commit API keys, passwords, or secrets. Add them to .gitignore before committing. If you accidentally commit secrets, they remain in Git history until it is rewritten—and you must rotate the credentials.
Next: Secure Communications
Your manifest is configured. Next, we'll set up SSH keys for secure communication with GitHub without repeatedly entering your account password.