How to add files to gitignore
Step-by-step instructions to ignore new or existing files.
Explore resourceProfessional .gitignore tools
Advanced troubleshooting for Python __pycache__, Node.js node_modules, Unity Library/, and all common "gitignore not working" scenarios. Get it fixed in 2025.
# Run these 3 commands in order: git rm -r --cached . git add . git commit -m "Fix .gitignore - stop tracking ignored files"
Safe to run: This won't delete your local files, only removes them from Git tracking.
__pycache__ folders and .pyc files still showing up in git status even after adding to .gitignore.
# Remove all Python cache files from tracking
find . -name "__pycache__" -exec git rm -r --cached {} + 2>/dev/null || true
find . -name "*.pyc" -exec git rm --cached {} + 2>/dev/null || true
# Add to .gitignore if not already there
echo "__pycache__/" >> .gitignore
echo "*.py[cod]" >> .gitignore
echo "*.pyo" >> .gitignore
# Commit changes
git add .gitignore
git commit -m "Stop tracking Python cache files"
git push🔗 Need a complete Python .gitignore?Use our Python gitignore template →
node_modules directory was committed before adding to .gitignore. Repository size is huge.
# Remove node_modules from tracking git rm -r --cached node_modules/ # Ensure it's in .gitignore echo "node_modules/" >> .gitignore # Remove duplicates from .gitignore sort .gitignore | uniq > .gitignore.tmp && mv .gitignore.tmp .gitignore # Commit changes git add .gitignore git commit -m "Remove node_modules from tracking" git push # Clean up local Git history (optional, advanced) git gc --prune=now --aggressive
Unity's Library/, Temp/, and Logs/ folders making repository gigabytes in size.
# Remove Unity generated folders from tracking git rm -r --cached Library/ 2>/dev/null || true git rm -r --cached Temp/ 2>/dev/null || true git rm -r --cached Logs/ 2>/dev/null || true git rm -r --cached UserSettings/ 2>/dev/null || true # Add Unity patterns to .gitignore cat >> .gitignore << 'EOF' [Ll]ibrary/ [Tt]emp/ [Ll]ogs/ [Uu]ser[Ss]ettings/ *.tmp *.bak EOF # Commit changes git add .gitignore git commit -m "Remove Unity generated files from tracking" git push
🎮 Unity developer?Get our complete Unity .gitignore template →
Your pattern config.js only ignores files in root, not in subdirectories like src/config.js.
Your global gitignore is conflicting with project-specific patterns.
Hidden characters, wrong line endings, or file encoding causing patterns to fail.
The --cached flag only removes files from Git's index (staging area), not from your working directory. Your local files remain untouched. It's the standard way to "untrack" files without deleting them.
Yes, when you push these changes, team members will need to pull them. The previously tracked files will be removed from their repositories too, but their local files will remain. This is usually the desired behavior.
Commit or stash your changes first before running git rm --cached commands. This prevents conflicts and ensures you don't lose any work.
For files like node_modules in Git history, consider using git filter-branch or BFG Repo-Cleaner to remove them from all commits. This requires force-pushing and team coordination.
Step-by-step instructions to ignore new or existing files.
Explore resourceSet up new repositories with correct defaults from day one.
Explore resourceUse the diff, validator and generator together to audit repositories.
Explore resourceBring failing patterns into the validator to confirm fixes instantly.