Read Anthropic’s case study about Graphite Reviewer

How to remove files from staging in Git

Kenny DuMez
Kenny DuMez
Graphite software engineer


Note

This guide explains this concept in vanilla Git. For Graphite documentation, see our CLI docs.


When working with Git you may need to occasionally unstage (remove from staging) files that have been added to the staging area by mistake or that require additional modifications before they can be committed. This guide provides detailed steps on how to remove files from staging, covering various scenarios that you might encounter.

The staging area in Git, also known as the index, is where Git holds files before they are committed to the repository. When you add changes to the staging area, you are preparing them to be included in your next commit. However, if you need to make further changes or decide not to commit them, you'll need to unstage these files.

  1. Removing a specific file from staging

    If you have added a file to the staging area and need to remove it, the git reset command can be used. This command will unstage the file but leave the changes in your working directory:

    Terminal
    $ git reset HEAD <file-name>

    For example, to unstage a file named example.txt:

    Terminal
    $ git reset HEAD example.txt

    After running this command, example.txt will still contain your changes, but it will no longer be staged for the next commit.

  2. Removing multiple files from staging

    If you have several files staged and want to unstage them, you can use the git reset command without specifying a file name:

    Terminal
    $ git reset HEAD

    This command will unstage all files currently in the staging area, leaving the changes in your working directory. You can then selectively re-stage only the files you want to commit.

  3. Unstaging all changes

    In case you want to remove all files from staging, you can use:

    Terminal
    $ git reset

    This is equivalent to git reset HEAD and will unstage all changes without removing them from your working directory.

  4. Using git restore to unstage files

    Starting with Git version 2.23, you can also use the git restore command to unstage files. This command is a bit more intuitive for those familiar with other version control systems:

    Terminal
    $ git restore --staged <file-name>

    To unstage multiple files, you can repeat the command for each file, or unstage all changes using:

    Terminal
    $ git restore --staged .
  • Verify before unstaging: Always check what is currently staged before unstaging files. Use git status to review the files that are about to be committed.
  • Regular commits: Make it a practice to commit changes frequently in small logical blocks. This reduces the complexity of handling many changes in the staging area.
  • Use meaningful commit messages: When you commit staged changes, use meaningful commit messages to describe what changes have been made and why. This practice is helpful for tracking changes and understanding the history of a project.

For further reading on unstaging files in Git see the official Git documentation.

Git inspired
Graphite's CLI and VS Code extension make working with Git effortless.
Learn more

Graphite
Git stacked on GitHub

Stacked pull requests are easier to read, easier to write, and easier to manage.
Teams that stack ship better software, faster.

Or install our CLI.
Product Screenshot 1
Product Screenshot 2