By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
A .gitignore file tells Git which files or patterns to ignore when tracking changes in a repository. A global exclude file does the same thing, but across all your local Git repos—no need to repeat rules in every project.
.gitignore
.env
node_modules/
*.log
*.pyc
node_modules
git clone
git status
.vscode/
*.pem
*.key
You inherit a legacy Python project. The repo is 1.2GB—mostly venv/, .DS_Store, and *.pyc files. git status takes 10 seconds to run. Your CI/CD pipeline fails because it’s trying to lint venv/bin/python. Fixing this starts with .gitignore.
venv/
.DS_Store
venv/bin/python
*
!
/
.log
!important.log
important.log
~/.gitignore_global
%USERPROFILE%\.gitignore_global
.git/info/exclude
debug.log
git check-ignore
git check-ignore -v path/to/file
git rm --cached
/temp/
temp/
!error.log
error.log
git --version
git init
Goal: Ignore node_modules/, .env, and *.log in a Node.js project.
bash cd ~/projects/my-node-app
bash touch .gitignore
nano
vim
bash nano .gitignore
# Environment variables .env .env.local .env*.local
# Log files *.log
# IDE/Editor files .vscode/ .idea/
# OS metadata .DS_Store Thumbs.db 5. Verify it works:bash touch .env test.log node_modules/dummy.js git status `` - Expected:.env,test.log, andnode_modules/should not appear ingit status`.
5. Verify it works:
`` - Expected:
,
, and
should not appear in
Goal: Ignore .DS_Store and .vscode/ across all repos so you never have to add them manually.
bash touch ~/.gitignore_global
bash nano ~/.gitignore_global
# Local overrides .env.local 4. Tell Git to use this file:bash git config --global core.excludesfile ~/.gitignore_global 5. Verify it works:bash cd ~/projects/another-repo touch .DS_Store git status `` - Expected:.DS_Storeshould not appear ingit status`.
4. Tell Git to use this file:
Goal: Figure out why debug.log is still showing up in git status.
bash git check-ignore -v debug.log
.gitignore:3:*.log debug.log
If no output: Git isn’t ignoring the file. Check for typos in .gitignore.
If the file was already tracked before adding it to .gitignore: bash git rm --cached debug.log git commit -m "Stop tracking debug.log"
bash git rm --cached debug.log git commit -m "Stop tracking debug.log"
Goal: You accidentally committed .env and pushed it. Fix it before it’s too late.
bash git rm --cached .env
bash echo ".env" >> .gitignore
bash git add .gitignore git commit -m "Ignore .env"
git filter-repo
git filter-branch
```bash # Install git-filter-repo (if not installed) pip install git-filter-repo
# Remove .env from history git filter-repo --invert-paths --path .env git push origin --force --all ```
id_rsa
credentials.json
*.sqlite3
git-secrets
bash git secrets --install git secrets --add 'aws_access_key_id|aws_secret_access_key'
dist/
build/
*.class
*.jar
.idea/
*.swp
*.sublime-workspace
Thumbs.db
desktop.ini
*.tmp
*.bak
npm-debug.log
CONTRIBUTING.md
.env.example
git rm -r --cached node_modules/
/*.log
git config --global core.excludesfile ~/.gitignore_global
git rm --cached .env
❌ Trap: .git/info/exclude (local-only, not shared).
"How do you stop tracking a file that’s already committed?"
git rm --cached file.txt
❌ Trap: rm file.txt (deletes the file from disk).
rm file.txt
"What does /temp/ match?"
src/temp/
tests/temp/
❌ Trap: Only temp/ in the root.
"You want to ignore all .log files except error.log. How?"
gitignore *.log !error.log
❌ Trap: Putting !error.log before *.log (order matters).
"How do you debug why debug.log isn’t ignored?"
git check-ignore -v debug.log
You have a Python project with: - A secrets.json file (accidentally committed).- A venv/ directory (not ignored).- A debug.log file (should be ignored).
secrets.json
Tasks:1. Stop tracking secrets.json without deleting it.2. Ignore venv/ and *.log in .gitignore.3. Verify debug.log is ignored.
# 1. Stop tracking secrets.json git rm --cached secrets.json # 2. Add rules to .gitignore echo "venv/" >> .gitignore echo "*.log" >> .gitignore # 3. Verify debug.log is ignored git check-ignore -v debug.log # Should show the .gitignore rule git status # Should not show debug.log or venv/
Why it works:- git rm --cached removes the file from Git’s index but keeps it on disk.- .gitignore rules apply immediately to untracked files.- git check-ignore confirms the ignore rule is working.
touch .gitignore
git check-ignore -v file.txt
!file.txt
git filter-repo --invert-paths --path .env
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.