Lessons · Git · files git should not watch
Files Git should never track
A .gitignore file lists patterns for files that should not be tracked: build output, logs, secrets, editor junk. Ignored files never show as untracked.
Hone is a place to practise programming. This is one of its lessons, written out in full and free to read without an account.
What it is for
Generated files change on every build and secrets must never enter history. One committed .env is in every clone forever, even after you delete it.
How to think about it
Write .gitignore first, commit it so the whole team shares it, then check git status: only real source should show. A file already committed needs git rm --cached, later in this stage, to stop being tracked while staying on disk.
Worked example
printf 'build/\n*.log\n' > .gitignorePatterns for files that should never be tracked.
mkdir -p build && echo out > build/app.js && echo log > run.logCreate some of them.
git status --shortOnly .gitignore shows: the build folder and the log are invisible.
git add .gitignore && git commit -m "Ignore build output and logs"The ignore file itself is tracked, so everyone shares it.
Your turn
Stop tracking a file that was committed before it was ignored.
git rm --cached
Try it in a real repository
The trap
.gitignore affects untracked files only. A file already committed stays tracked until git rm --cached removes it from the index, which is a later lesson in this stage.