Ignoring Files
Create a .gitignore file
List patterns for files Git should leave untracked. Commit .gitignore itself so everyone on the project shares the same rules.
echo '.env' >> .gitignore
echo '__pycache__/' >> .gitignore
echo '*.log' >> .gitignore
git add .gitignore
git commit -m "Ignore env files, caches, and logs"
Use common patterns
*.logignores log files in any folderbuild/ignores a directory named build.envignores a local secrets file!important.logcan re-include an exception when needed
Understand already-tracked files
Ignoring only affects untracked files. If Git already tracks a file, remove it from the index without deleting your working copy, then commit.
git rm --cached secrets.txt
git commit -m "Stop tracking secrets.txt"
Check what Git sees
Status should no longer list ignored untracked files. That is the goal: a clean view of real project changes.
git status
Comments
One comment per signed-in account. Comments are saved with this page’s URL.