Unstaging Files: How to Use git restore --staged
Learn how to remove files from the staging area using git restore --staged. Safely undo your staging steps without losing your local file changes.

Previously in this course, we explored Undoing Uncommitted Changes with Git Restore to discard modifications in your working directory. This lesson focuses on the opposite problem: what happens when you've already moved files into the staging area but aren't ready to commit them.
When working with Git, it is easy to accidentally run git add . and include files you didn't intend to track, or perhaps you staged a file that isn't quite finished yet. Learning to "unstage" is a critical skill for maintaining clean, logical commit history.
Understanding the Staging Area
As we covered in Understanding the Git Lifecycle: Staging Area & Working Directory, the staging area acts as a "waiting room" for your next commit. When you use git add, you are telling Git, "Prepare these specific changes for the next snapshot."
Sometimes, you might add too many files or realize a specific file needs more work before it belongs in a commit. You don't want to delete the file from your computer; you simply want to remove it from the staging area so it stays in your working directory as an unstaged change.
Removing Files with git restore --staged

The modern, safe way to remove files from the staging area is the git restore command with the --staged flag. This command tells Git to take the file out of the "waiting room" while keeping your local modifications exactly as they are.
Worked Example
Imagine you are working on our project and you accidentally add a temporary log file to the staging area.
-
First, check your status to see the current state:
Bashgit statusOutput:
TEXTChanges to be committed: modified: project-notes.txt new file: temp-log.txt -
You realize
temp-log.txtshould never be committed. Instead of panicking, you use the restore command:Bashgit restore --staged temp-log.txt -
Run
git statusagain to verify:TEXTChanges to be committed: modified: project-notes.txt Untracked files: temp-log.txt
Notice that the file is no longer in the "Changes to be committed" section. It has been safely moved back to your working directory, where you can now Ignoring Files: Mastering .gitignore for Cleaner Repositories if you don't want to track it at all.
Hands-on Exercise
To practice this workflow:
- Create a new file named
draft.txtand add some text to it. - Run
git add draft.txtto stage the file. - Check
git statusto confirm it is staged. - Run
git restore --staged draft.txtto unstage it. - Confirm the file still exists in your folder, but is no longer staged.
Common Pitfalls
- Confusing restore with remove: Beginners often reach for
git rm, which actually deletes the file from your disk. Remember:git restore --stagedis for changing your mind about the commit, not for deleting your work. - Forgetting the flag: If you run
git restorewithout--staged, Git will try to discard the changes inside your file, reverting it to the version in your last commit. Always include--stagedif you only want to change the staging status.
FAQ
Q: Does unstaging files delete my code?
A: No. git restore --staged only changes the status of the file in Git's index; it leaves your actual file contents untouched.
Q: Can I unstage multiple files at once?
A: Yes. You can pass multiple filenames (e.g., git restore --staged file1.txt file2.txt) or use a directory path to unstage everything within that folder.
Q: Is there an older way to do this?
A: You may see references to git reset HEAD <file>. This was the standard command before git restore was introduced in Git version 2.23. While it still works, git restore is preferred for its clarity and safety.
Recap

You now know how to recover from over-eager staging. By using git restore --staged, you maintain precise control over what enters your repository history, ensuring only intended changes are captured in your commits. This is a vital step in maintaining the "clean, atomic commits" that professional teams rely on.
Up next: Navigating Commits — viewing past states and moving through your project history.
Work with me

VPS Server Setup, Deployment & Hardening
Get your app live on a fast, secure server — properly configured, hardened, and deployment-ready. No more wrestling with the command line.

CI/CD Pipeline & Docker Containerization
Ship with confidence: automated CI/CD pipelines and Docker setups so every push is tested and deployed — no more manual, error-prone releases.


