Synopsis
git restore [--staged] [--source=<tree>] [-p] <pathspec>...
Description
The git restore command, introduced in Git 2.23, replaces the file-restoring half of git checkout. It is purpose-built for two cases: discarding unstaged changes in the working tree (default behavior) and unstaging changes from the index (with --staged). The cleaner separation makes the tool less error-prone than git checkout.
You can restore from any source: another commit, a branch, or a tag. Combined with -p, you can interactively pick which hunks to restore. git restore never modifies branches or HEAD — it only touches files.
In day-to-day use, git restore integrates closely with shell aliases, editor plugins, and continuous integration. Power users often add aliases that combine flags they always pass, or wrap the command in scripts that enforce team conventions. Output formatting can be customized via Git config — pretty formats, color schemes, and pager behavior are all tunable. When something goes wrong, the first diagnostic step is usually to re-run the command with GIT_TRACE=1 in the environment, which reveals the underlying plumbing calls. For unusual situations, the --help output (git restore --help) opens the full manual page with details on every option, including those rarely used in casual workflows but essential for debugging or scripting at scale.
Understanding how git restore interacts with the rest of Git's data model — the object database, the index, refs, and the working tree — pays dividends. Each command operates on some subset of these pieces, and knowing which it touches helps predict outcomes and recover from mistakes. Reading the official Git documentation alongside hands-on practice in a throwaway repository is the fastest way to internalize the nuances. Most production issues with Git stem from one of three causes: surprising default behavior, partial network operations, or rewriting history that was already shared. A working mental model of git restore's side effects helps avoid all three.
Common Options
| Option | Description |
|---|---|
--staged | Restore the index instead of the working tree (i.e., unstage). |
--worktree | Restore the working tree (default). |
--source=<tree> / -s | Restore from a specific commit, branch, or tag. |
-p, --patch | Interactively pick hunks to restore. |
--ours / --theirs | During a conflict, restore one side. |
-q, --quiet | Suppress progress. |
Examples
git restore src/main.c
# Discard unstaged changes in main.c
git restore --staged config.yml
# Unstage a file (keep working-tree changes)
git restore --source=HEAD~3 README.md
# Bring back README.md as it was 3 commits ago
git restore -p
# Interactively pick hunks to discard
Common Mistakes
git restore on a file with unsaved changes silently overwrites them — there is no confirmation prompt and no easy undo. Stash first if uncertain. Beginners sometimes confuse --staged with git reset --hard; --staged only touches the index, leaving working-tree edits intact.
Related Commands
git reset, git checkout, git stash, git revert