Lesson 15 · Everyday work
Ignore files and clean untracked work safely
Commit the course ignore policy, then preview and remove only a disposable untracked scratch file. Keep ignored build output, tracked work and recovery scope separate.
- Level: Intermediate
- 6 min read
- 6 min video
- Updated
- Before this lesson: Read the comparison before judging a change
Progress saved in this browser.
Playing loads the video from YouTube (privacy-enhanced mode).
What you will learn
- Explain ignore rules versus tracked files.
- Preview a narrowly scoped clean.
- Inspect the app's exact removal list.
- Distinguish native deletion from app snapshots.
Before you start
Start where lesson 14 ended: main/H7 clean, the minimal .gitignore contains dist/ only, tag v0.1.0 is fixed at H7. The video adds a generated dist/index.html, which the rule already hides.
The video was recorded with Git 2.52.0 and GitTree 2.0 on Ubuntu 24.04: the ignore file, its commit, the scratch file and the clean were done in the app; the before state, the previews and the checks ran in the terminal, with a separate copy for the previews. Nothing was run on macOS or Windows, and Ubuntu is the only Linux system recorded. GitTree's source Git floor is 2.39.0.
GitTree asks you to sign in; the Free plan then covers every step here. No provider account, Pro/trial, API credential or internet service is needed. A local bare origin is not GitLab or CI. All identities use example.com; never run this lesson inside a source checkout.
Make mutations through either GitTree or the native path at identical inputs, not both consecutively. Read-only verification can follow either. Any preparation described as terminal work is labeled native preparation, never an invented app feature.
Concept and state effects
Ignore rules normally hide untracked candidates; they do not stop tracking an already indexed path, scrub history or protect secrets. Commit the shared policy like any other file.
A clean operation removes untracked paths in its scope. Native git clean has no built-in recovery snapshot; deleting an untracked file is not recoverable from ordinary commit history unless separately preserved.
GitTree's Clean Untracked Files… builds an exact list and protects listed bytes before removal. Options Include ignored files and Only ignored files change scope and are mutually exclusive. Source protection is not proof a particular Undo was recorded.
Saving/committing .gitignore changes index/tree/main. Cleaning scratch removes that untracked disk file only; it does not make a commit or update remote refs. Ignored dist stays with the default clean options.
Prepare the exact project state
Use only original course repository. Save full IGNORE, stage and commit first. Then create full SCRATCH; it is deliberately outside ignored scratch/ so the default clean list can show it. Preserve a separate copy outside the demo if practicing native removal.
Complete file inputs
Save only at the phase named below. These are full UTF-8/LF bodies with a final newline; never paste Markdown fences. Unchanged runnable files inherit the named input. Versions in separate variants must not overwrite the original.
.gitignore — IGNORE
node_modules/
dist/
coverage/
reports/
.course-cache/
*.log
scratch/course-scratch.txt — SCRATCH
Disposable course scratch. No useful work.In GitTree
Palette: Command+Shift+P (Ctrl+Shift+P on Ubuntu); type the exact named command and select it. Named-ref actions use that row's context menu, not an argument-free palette shortcut.
- Palette Edit .gitignore… opens “.gitignore in gittree-features”. Click Rules, one per line, select all, and type (or paste) the full IGNORE body; Save. This writes the file, not a commit. (The dialog also has Add Template and a Why is this ignored? check for a path.)
- Show Working Changes; review .gitignore only, Stage File; Summary chore: ignore generated course files; Commit Changes to 1 File once.
- New File… → course-scratch.txt → Create; save exact SCRATCH, no staging. Confirm it is untracked.
- Run the native path-scoped dry-run below. If any different path is listed, stop before removal.
- Palette Clean Untracked Files… opens “Clean untracked files in gittree-features?”. It reads “1 file, 0 folders (0 ignored), 43 B” and lists course-scratch.txt; below the list it says that a recovery snapshot of every listed file is saved under refs/ogt/trash before anything is removed, and that Undo puts the files back where nothing new has taken their place.
- Leave Include untracked folders, Include ignored files and Only ignored files off. Expected candidate is course-scratch.txt only; Cancel if useful work appears.
- Choose Remove 1 Item once and wait for actual result. The app protects bytes first; capture that evidence before claiming Undo.
- Verify clean status and dist/index.html ignored. Do not delete snapshots or enable ignored cleaning to beautify the view.
For every ordinary commit: Summary is the stated subject; Description empty; Amend Previous Commit, Skip Hooks, Add Signed-off-by, Different Author, Push After Commit and Allow Empty Commit off; no co-authors. Stage only the named files, then Commit Changes to N Files once (File for one), or Command+Enter as an alternative. Wait for the real result. A lesson that explicitly amends changes only that stated option.
In the terminal
Save IGNORE first; native commit alternative:
git add -- .gitignore
git commit --quiet -m "chore: ignore generated course files"
git check-ignore dist/index.htmlObserved output:
dist/index.htmlCreate exact SCRATCH only after that commit, preserve it externally if needed, then:
git clean -n -- course-scratch.txtObserved:
Would remove course-scratch.txtOnly after confirming this disposable path, native alternative (not after app success):
git clean -f -- course-scratch.txt
git status --shortObserved removal:
Removing course-scratch.txtStatus is silent. This native -f is limited to the named disposable file, not -fdx or a broad cleanup. Native Git did not make an app snapshot. Changed-input nonmutating previews, as they ran in a separate copy: git clean -n -X printed nothing, because without -d Git does not enter the ignored dist/ folder; git clean -n -x listed only course-scratch.txt for the same reason; git clean -n -x -- course-scratch.txt dist/index.html, which names both paths, listed both. Naming a path is what widens the scope. Never replace the scoped removal with either expanded destructive form.
Result
Where you end: Main has the chore: ignore generated course files commit I8 with full IGNORE; course-scratch.txt absent after explicit clean, work/index clean, dist ignored, tag/server refs unchanged.
Common mistakes
- Assuming ignored tracked files leave history.
- Using -x or app ignored options without scope review.
- Expecting native clean to have app Undo.
If something goes wrong
Cancel if the preview differs. Native removal needs the separate preserved file to restore it; app Undo depends on the real snapshot/journal and current paths, not a promise covering any deletion.
Check your understanding
Answer each question, then read why. Questions marked “Required” count toward completing the lesson.
0 of 6 correct
Answer the required questions correctly to complete the lesson.
Checked in this browser.
Practice
Verify IGNORE is committed, scratch absent and dist ignored. In a separate preview only, predict which ignored candidates appear with -X versus -x without deleting them.
Your own confirmation: the site cannot see your computer.
To complete the lesson, answer the required questions correctly and confirm the practical exercise.
Recap
- Ignore is not untracking.
- Clean scope is explicit.
- Recovery depends on preserved bytes.
Related
Glossary terms introduced
Ignore — تجاهُل; clean — تنظيف; untracked — غير متتبَّع; recovery snapshot — لقطة استعادة.
Video transcript
The narration of the video, cue by cue.
Show the transcript
- Start from the exact checkpoint.
- Name the branch, index and working version.
- Prepare only the isolated course copy.
- Save the exact shared ignore policy.
- Commit only the ignore file.
- Keep the scratch file deliberately untracked.
- Preview the exact named path first.
- Read every removal candidate.
- Do not widen the clean options.
- Remove only the disposable file.
- Verify what stayed as well as what disappeared.
- Does ignore erase tracked history?
- Rules hide untracked candidates; they do not rewrite history.
- What remains after scoped clean?
- Only the named untracked scratch is removed with these options.
- Does cleaning make a new commit?
- The operation removes disk bytes outside the index.
- Change input to include ignored files: scope?
- Expanded options change candidates; preview again before acting.
- Native clean ran. Is app Undo guaranteed?
- Native clean creates no GitTree journal or untracked-content backup.
- What proves the intended clean?
- Check both removed and preserved state with the named queries.
- Verify the actual result, not just a message.
- Predict the changed input before acting.
- Preserve useful work before recovery.
- Prove the checkpoint before continuing.
- Keep the verified result for the next step.