If you have added files to the stage area using the git add command but you want to remove or upstage them, you can simply make use of the git restore command,
Intrestingly if you run the git status command and you have some files in the staging area, the command itself shows hints on how to restore files,
% git status
On branch main
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: Sample.java
Untracked files:
(use "git add <file>..." to include in what will be committed)
Main.java
So, to unstage the file Sample.java execute the below git command,
% git restore --staged Sample.java

How to unstage all files?
Just add a . to restore all files that are staged,
% git restore --staged .
❗️Note: If you have a staged file and have made modifications to that file and you restore it, the local changes will be discarded i.e. lost, so be careful (unless you are using an IDE that maintains a history of a file like - Eclipse, VS Core or IntelliJ
Have Questions? Post them here!
- How to ignore files in git using .gitignore file
- How to update expired GitHub token on local git remote config
- How to undo last Git Commit on Local Repository?
- Git Commit - Author identity unknown, Please tell me who you are email
- Git: Step-by-Step - How to Push Local Brach to GitHub
- [Solution] fatal: not a git repository (or any of the parent directories): .git
- Remove git config at Local, Global or System Levels?
- Change the default git branch name from master to main
- fix fatal: --local can only be used inside a git repository error
- Git Remove Untracked Files using Command
- How to remove or unstage a file from git staged area
- Fix Git: Warning: could not find UI helper GitHub.UI on Windows
- Fix [oh-my-zsh] Cant update: not a git repository
- Get List of all local branches git command
- Github: fatal: Authentication failed Support for password was removed on August 13, 2021
- [fix] fatal: this operation must be run in a work tree in git
- How to Install Git on Windows
- Perform an Empty Commit in Git without anything in Staging Area
- Rename git branch on Local and GitHub Remove using Command
- Fix: error: could not lock config file /etc/gitconfig: Permission denied
- Get the file location of git config values
- Git: Delete Branch Locally and Remotely at Origin
- fatal: Unable to create '/c/git_repo/.git/index.lock': File exists. If no other git process is currently running, this probably means a git process crashed in this repository earlier.
- Github: How to Invite Collaborators
- How to change directory in Git bash
- Change Android EditText Cursor Height - Android
- Top 3 Awesome Text Editors developers prefer at workplace - Sublime
- [fix] Java JDBC ConnectException: Connection refused - Java
- npm WARN saveError ENOENT: no such file or directory, open /mnt/c/package.json - JavaScript
- Chrome : When Adobe flash player has finished updating, reload this page to active it - Chrome
- Add Text at Start and End of Each Line Notepad++ - NotepadPlusPlus
- Convert Java Object to JSON using Jackson Library - Java
- 30+ Zoom video communications application shortcuts for macOS - MacOS