Git FAQ

Frequently asked questions around Git and Version Control.

How to Unstage Files in Git

Git has a concept called "Staging Area" to determine which changes should go into the next commit. And it's important to understand that changes are NOT added to the Staging Area automatically: they have to be manually and explicitly added with the git add command. Adding files to the Staging Area like this is often called "staging files for the next commit."

In this short article, we'll discuss how to do the opposite: how to unstage a file in Git, i.e. removing it from the Staging Area to prevent it from being included in the next commit.

The Git Cheat Sheet

No need to remember all those commands and parameters: get our popular "Git Cheat Sheet" - for free!


Using git restore to Unstage

The git restore command is perfect when you have already added a file to the Staging Area and then changed your mind:

$ git restore --staged myFile.js

This will remove the file from the Staging Area, making sure that it will NOT be part of the next commit.

In case you also want to discard the local changes in this file, you can simply remove the --staged option:

$ git restore index.html

This will discard any local modifications in this file and reset it to its last committed state. Please be vey careful with this command: discarding uncommitted local changes cannot be undone!

Tip

Unstaging files in Tower

In case you are using the Tower Git client, untaging a file is as simple as unchecking its "Status" checkbox in the Working Copy view:

Using git reset to Unstage

Apart from restore you can also use git reset to unstage changes. If you're using a Git version older than 2.23, you will have to use reset because restore is quite a new feature in Git.

$ git reset myFile.js

Exactly like git restore --staged, this makes sure the file is NOT included in our next commit. The local changes themselves are not affected by this command.

Unstaging All Files at Once

Sometimes, you might want to unstage all of the files you had already added to the Staging Area. In such a situation, you can use git reset without further options:

$ git reset

The Staging Area will be emptied (but your local changes themselves are left untouched).

Learn More

About Us

As the makers of Tower, the best Git client for Mac and Windows, we help over 100,000 users in companies like Apple, Google, Amazon, Twitter, and Ebay get the most out of Git.

Just like with Tower, our mission with this platform is to help people become better professionals.

That's why we provide our guides, videos, and cheat sheets (about version control with Git and lots of other topics) for free.