Weekly Git Command #2: git restore

Weekly Git Command #2: git restore
For a long time, I used git checkout for almost everything, switching branches, discarding changes, restoring files.
While contributing during the Outreachy contribution phase, I learned that Git now provides clearer, more purpose-built commands for these actions. One of them is git restore.
What git restore does
git restore is used to restore files in your working directory or staging area to a previous state.
In simple terms, it helps you undo changes safely and explicitly.
Common use cases
Discard unstaged changes in a file
git restore file.txt
This resets file.txt back to the last committed version.
Unstage a file (without losing changes)
git restore --staged file.txt
This removes the file from the staging area but keeps your edits.
Restore multiple files
git restore .
Restores all modified files in the working directory.
Why this matters
Previously, many of these actions were done using git checkout, which made it easy to accidentally do the wrong thing.
git restore makes your intent clear:
restore→ undo file changesswitch→ change branches
That clarity alone makes it worth learning.
Final thoughts
git restore is a great example of how Git is evolving to become more user-friendly without losing power.
This is part of my Weekly Git Command series, where I share Git commands I’m learning while contributing to Git via Outreachy.




