AI Hints
Home›Git & GitHub Tutorial›Cleaning Up the Folder
Git & GitHub · Lesson 37 of 144

A Completely Fresh Start

Restore everything.

⏱ 2 min read▶ Video at 40:07🎓 Free
Watch this lesson in the Git & GitHub courseWatch on YouTube ↗Full Git & GitHub course

Sometimes you want to throw away every change, in every file, and get back to the last commit. A completely fresh start. You already know the pieces.

A Completely Fresh Start
From the video: A Completely Fresh Start
  • Throw away every change
  • Back to the last commit
  • You know the pieces

Restore everything

We've changed two tracked files, and made some junk. Git restore, with a dot, restores every tracked file in the folder. Then git clean dash f d removes the untracked junk. Status is completely clean. It's as if we just cloned the project.

git
git status --short
 M index.html
 M style.css
?? build/
?? draft.html
?? notes.tmp
git restore .
git clean -fd
Removing build/
Removing draft.html
Removing notes.tmp
git status
On branch main
nothing to commit, working tree clean

Restore versus clean

Remember the difference. Restore works on tracked files, putting them back to the last commit. Clean works on untracked files, deleting them. Together, they give you a fresh start.

git restore .

  • Tracked files
  • Back to last commit

git clean -fd

  • Untracked files
  • Deleted for good

Summary

Git restore dot, and git clean dash f d, give you a completely fresh start. Next, a practice round of undo challenges.

Key takeaways
  • git restore .
  • git clean -fd
  • A fresh start
Next up: Practice: Undo Challenges — choose the right undo