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!
- [Fixed] Git Clone git@github.com: Permission denied (publickey) Could not read from remote repository Fatal error
- Github: How to Invite Collaborators
- Git Commit - Author identity unknown, Please tell me who you are email
- [Solution] fatal: not a git repository (or any of the parent directories): .git
- [fix] zsh: command not found: git
- Github: fatal: Authentication failed Support for password was removed on August 13, 2021
- Get List of all local branches git command
- Git Revision Questions Before the Interview
- git fatal: Authentication failed error [fix]
- How to Install Git on Ubuntu Linux
- GitHub: How to Search Code
- How to change Git Default Author and Committer details in Eclipse
- How to check your installed version of Git
- Install GitHub Command Line Tool on Mac
- How to Merge Branch into Master Branch
- Perform an Empty Commit in Git without anything in Staging Area
- Git Fix: fatal: refusing to merge unrelated histories Error
- How to undo last Git Commit on Local Repository?
- git command to remove/unstage files from staging area
- Step-by-Step: Setting up Docker + Ubuntu Linux + Git + GitHub Tutorial
- Remove git config at Local, Global or System Levels?
- Fix [oh-my-zsh] Cant update: not a git repository
- Git Config Command - A Deep Dive
- 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.
- How to change directory in Git bash
- Clone a particular remote brach using git clone command - Git
- Ways to Convert Integer or int to Long in Java - Java
- Remove Now Playing icon from macOS Big Sur Menu Bar - MacOS
- WhatsApp Web escanner - WhatsApp
- [Android Studio] failed to find Build Tools revision 23.0.0 rc1 - Android-Studio
- Encode or Decode Base64 String using Mac Terminal Command - MacOS
- Git Rename master branch make to main using Command - Git
- How to display Toast on Button Click : Android - Android