How to remove files from staging in Git?

You have added a file to a staging area using git add command, and now you want to unstage that file then this tutorial is for you. Here, you will learn how to unstage files in Git.

git status command is used to check whether a file is in a staging area or not. When a file is in a staging area then on running git status command, you will get the following output:

On branch master
Changes to be committed:
  (use "git reset HEAD ..." to unstage)

        modified:   groceries.html

Here, you can see that groceries.html is in a staging area.

To remove a file from staging, you need to run git reset HEAD filename. In this case, the file is groceries.html, and the command will be git reset HEAD groceries.html

Note: HEAD is always written in a capital letter.

After that, you should run git status to ensure that the file is removed from a staging area.

On branch master
Changes not staged for commit:
  (use "git add ..." to update what will be committed)
  (use "git checkout -- ..." to discard changes in working directory)

        modified:   groceries.html

no changes added to commit (use "git add" and/or "git commit -a")

You can see that the file groceries.html is removed from a staging area.

You can visualize the entire process using a state diagram.

git remove files from staging

How to unstage all files in Git?

There are two ways to unstage all the files:

  1. git reset HEAD .

    Period or dot means all the files in a Git repo that you have staged recently.

  2. git reset HEAD groceries.html bakery.html

    Specify the files after HEAD which you want to unstage. Make sure you separate filenames with space. In this case, two files are specified: groceries.html and bakery.html

Note: You can use any method that you find suitable to use.