Before this lesson
First distinguish the worktree, index and HEAD.
Use Git 2.35+ and a Bash-compatible terminal, such as Git Bash on Windows. Each complete example creates an independent temporary directory. Run it only in that practice repository. Configuration is repository-local and uses a practice identity. Temporary directories are not automatically removed; clean them up after finishing.
What you will be able to do
Trace file history and distinguish ignored files from tracked files.
Understand the mechanism
git log --oneline summarizes history; --graph --all exposes branch relationships. git show inspects a commit or a file at a revision. Use git log --follow -- path to follow one file across renames.
.gitignore describes untracked paths that should not be added automatically. It neither untracks committed files nor erases historical secrets. Revoke or rotate exposed credentials before following a history-cleanup procedure.
git check-ignore -v identifies the matching ignore rule, helping diagnose unexpectedly ignored files. This example ignores build while continuing to track source notes.
Runnable example
lab=$(mktemp -d)
cd "$lab"
git init -b main .
git config user.name "Honeysuck Learner"
git config user.email 'learner'@'example.invalid'
git config commit.gpgsign false
git config core.autocrlf false
printf 'Start learning\n' > notes.txt
git add notes.txt
git commit -m "Start learning notes"
printf 'build/\n*.tmp\n' > .gitignore
mkdir build
printf 'generated\n' > build/output.txt
git add .gitignore
git commit -m "Ignore generated files"
printf 'Review history\n' >> notes.txt
git add notes.txt
git commit -m "Add review step"
git log --oneline -- notes.txt
git diff HEAD~1 HEAD -- notes.txt
git check-ignore -v build/output.txt
git ls-files
Trace and verify
notes.txt has two relevant commits. The diff adds Review history, check-ignore identifies build/, and ls-files lists only .gitignore and notes.txt.
Common mistakes and boundaries
Do not ignore an entire project root to hide noise. git rm --cached can untrack a file while retaining the working copy, but the change must be committed and affects collaborators.
Practice challenge
Create draft.tmp and identify its matching rule.
Reference solution and reasoning
git check-ignore -v draft.tmp points to *.tmp. Normal short status omits it, while git status --ignored reveals ignored entries.