Unstage a file I added by mistake
I ran git add on a file that should not be in this commit.
The problem
I ran git add on a file that should not be in this commit.
How the practice repository looked before
## main M notes.txt A secret.txt
7c26407 Add line two de1ce31 Add notes
The fix
Check the result
M notes.txt ?? secret.txt
Why this works
git restore --staged takes the file out of the staging area and leaves the file itself alone. In the short status, the first column is the staging area and the second is your folder: M in the first column means modified and staged, ?? means not tracked by Git.
If this is not quite your case
Older guides use git reset HEAD <file> for the same job, and it still works. git restore --staged was added in Git 2.23 to give the job a clearer name. If the file was never committed, after unstaging it is simply untracked again, as the ?? shows.
This is an independent guide. It is not connected with the Git project, GitHub, GitLab or any company named here. Every command below was run on 14 November 2026 with the real program (git version 2.56.0.windows.4) in a new empty practice repository; the output shown is what it printed. Facts about options were read in the official Git documentation on 14 November 2026.