The staging area (index) acts as a preview zone between your working file directory and your committed repository history.
flowchart LR
W["Working Directory<br/>(Local Files)"] -->|"git add"| S["Staging Area<br/>(Index File)"]
S -->|"git commit"| R["Commit History<br/>(Git Object Database)"]
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 filegit add --all or git add -A - Stage all changesgit status - See what is stagedgit restore --staged <file> - Unstage a filegit addTo 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 <file>..." to unstage)
new file: index.html
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.
git statusSee 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 <file>..." to unstage)
new file: README.md
new file: bluestyle.css
new file: index.html
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.
git restore --staged <file> to unstage it.git add <file> again before you commit.git status to see what will be committed.Execute the following terminal commands to work with this concept in your workspace:
# Stage a specific file
git add index.html
# Stage all modified and new files
git add .
# Unstage a file while keeping local edits
git restore --staged index.html
Fix CORS bug rather than Fixed CORS bug).git diff to review unstaged modifications before adding files to the index.git switch -c <branch-name> to preserve edits.git restore --staged <filename> to remove the file from the index without altering your local workspace copy.Open your terminal in a test project directory, execute git status, and verify your current working tree state. Practice running git log --oneline to review commit history.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With