Menu
×
     ❯   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING BASH RUST

Git Staging Environment


What is the Staging Environment?

The staging environment (or staging area) is like a waiting room for your changes.

You use it to tell Git exactly which files you want to include in your next commit.

This gives you control over what goes into your project history.

Here are some key commands for staging:

  • git add <file> - Stage a file
  • git add --all or git add -A - Stage all changes
  • git status - See what is staged
  • git restore --staged <file> - Unstage a file

Stage a File with git add

To add a file to the staging area, use git add <file>:

Example

git add index.html

Now index.html is staged. You can check what is staged with git status:

Example

git status
On branch master

No commits yet

Changes to be committed:
  (use "git restore --staged ..." to unstage)
    new file: index.html


Stage Multiple Files (git add --all, git add -A)

You can stage all changes (new, modified, and deleted files) at once:

Example

git add --all

git add -A does the same thing as git add --all.


Check Staged Files with git status

See which files are staged and ready to commit:

Example

git status
On branch master

No commits yet

Changes to be committed:
  (use "git restore --staged ..." to unstage)
        new file:   README.md
        new file:   bluestyle.css
        new file:   index.html

How to Unstage a File

If you staged a file by mistake, you can remove it from the staging area (unstage it) with:

Example

git restore --staged index.html

Now index.html is no longer staged. You can also use git reset HEAD index.html for the same effect.


Troubleshooting

  • Staged the wrong file? Use git restore --staged <file> to unstage it.
  • Forgot to stage a file? Just run git add <file> again before you commit.
  • Not sure what's staged? Run git status to see what will be committed.

Exercise?What is this?
Test your skills by answering a few questions about the topics of this page

What is the purpose of the staging area in Git?




×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2025 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.