Interview Q&A / Git & GitHub

BeginnerQuick answer1 min readUpdated 3 Oct 2026

How do you unstage a file you added by mistake?

SHORT ANSWER

Use git restore --staged file, or the older git reset HEAD file. The file leaves the staging area but your edits stay in the working directory.

Explain it simply

You ran git add . and the staging area now includes a file with a password in it. Unstaging is like taking an item back off the billing counter. You still own it; it just will not be billed.

Both commands copy the file's version from the last commit back into the index. Your working file is untouched. If the file is newly created, it becomes untracked again. This works before committing; after a commit you need amend or reset.

Example

bash
git add .
git status                       # config.env is staged
git restore --staged config.env
# older equivalent
git reset HEAD config.env

What to say in the interview

"I run git restore --staged file, or git reset HEAD file on older versions. It removes the file from the index while keeping my changes in the working directory, and it only works before the commit is made."

#git#staging#undo

Related questions

Practise more Git & GitHub questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open Git & GitHub quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.