Skip to content

Instantly share code, notes, and snippets.

@jorgeadev
Last active June 25, 2025 22:02
Show Gist options
  • Select an option

  • Save jorgeadev/3e4bd1c8176e6bfcdb368b7ee10c8e1b to your computer and use it in GitHub Desktop.

Select an option

Save jorgeadev/3e4bd1c8176e6bfcdb368b7ee10c8e1b to your computer and use it in GitHub Desktop.
This quick reference explains how to remove or unstage files in Git — depending on whether you want to keep the file or not

🧠 Git Cheat Sheet: Removing and Unstaging Files

📌 Unstage a File but Keep It

If you've added a file with git add but haven't committed it yet, and you want to remove it from the next commit without deleting it from your working directory, use:

git restore --staged <file>

git restore --staged config.json

This removes config.json from the staging area so it won’t be part of the next commit, but it will remain on your filesystem If you don’t want to keep the file (neither in Git nor on disk), and you've already staged it (with git add), then you can

git rm <file>

git rm secrets.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment