How to Undo a 'git add'

Published Dec 18, 2021  ∙  Updated Jan 3, 2022

How do we undo a git add command?

We can do this quite simply using git reset or git restore (whichever you’d like).

Undo git add for a single file

Let’s say we want to undo git add for a single file index.js. We could run either command below.

git reset index.js
# OR
git restore --staged index.js

After running either command, the file will be removed from the current index. It will not be included in the commit.

Undo git add for all files

Let’s unstage all files in our repository.

git reset
# OR
git restore --staged . # Run from root of directory