The git status command is one of the most commonly used Git commands. It shows the current state of your working directory and staging area.
git status frequently while
working with Git. It helps you understand which files are modified,
staged, untracked, or ready to be committed.
git status displays information about the current state of a Git repository.
git status
It helps you see what has changed since the last commit.
Git does not automatically show you every change in your project.
The git status command helps you check what Git currently
knows about your files.
It is useful before staging and committing changes.
The basic syntax is very simple:
git status
Run this command from inside a Git repository.
Suppose you have a project called my-project. First enter the project:
cd my-project
Then run:
git status
The status output normally shows the branch you are currently working on.
For example, Git may display:
On branch main
This tells you that the current branch is main.
If there are no changes to commit, Git may show a message similar to:
nothing to commit, working tree clean
This means there are no detected changes waiting to be committed.
A file that Git is not currently tracking can appear under Untracked files.
Untracked files:
index.html
You can stage the file using:
git add index.html
An untracked file is a new file in your working directory that has not yet been added to Git's staging area.
For example, after creating:
index.html
Git can show it as an untracked file.
When a tracked file is changed after the last commit, Git can show it as modified.
Changes not staged for commit:
modified: index.html
This means the file has changes that have not yet been staged.
After modifying a file, you can stage it with:
git add index.html
Run git status again to see the new state.
After staging a file, Git can show it under:
Changes to be committed:
This means the changes are currently in the staging area and can be included in the next commit.
Changes to be committed:
modified: index.html
The file has been staged and is ready for a commit.
To stage all changes in the current directory, use:
git add .
Then check the result:
git status
It is good practice to run git status before creating
a commit.
git status
git commit -m "Update website"
This allows you to review which changes are staged.
After committing all staged changes, run:
git status
If no additional changes exist, Git may report:
nothing to commit, working tree clean
If a tracked file is deleted from the working directory, Git can show the deletion in the status output.
deleted: old-page.html
The deletion can then be staged before committing.
You can stage a deletion with:
git add old-page.html
Another command commonly used for staging file deletions and other changes is:
git add -A
Git may recognize a file rename when changes are staged. The status output can show a renamed file.
renamed: old.html -> new.html
Git uses similarity between file contents when detecting renames.
Git provides a compact status format using:
git status --short
This is useful when you want a shorter output.
The short status format uses two columns to represent the state of files.
M index.html
A style.css
?? script.js
The two positions represent different types of changes in the index and working tree.
The status command helps you distinguish between changes that are only in the working directory and changes already staged in the index.
Working Directory
↓
git add
↓
Staging Area
↓
git commit
git status
# edit index.html
git status
The second status check can show that index.html has been modified.
git add index.html
git status
The modified file will now appear as a change staged for the next commit.
git commit -m "Update index page"
git status
If no additional changes exist, the working tree can become clean.
After creating a repository with:
git init
you can immediately check its state using:
git status
This is useful for confirming that you are working inside the correct repository.
Git status can show the current branch at the beginning of its output. For example:
On branch main
This is useful when working with multiple branches.
git status
git status --short
git add .
git status
git commit -m "Update project"
git status
This simple sequence helps you understand the state of your project before and after a commit.
mkdir website
cd website
git init
touch index.html
git status
git add index.html
git status
git commit -m "Add index page"
git status
This example demonstrates how git status can be used
throughout the basic Git workflow.
The git status command gives you a clear view of the current state of your Git repository.
It can help you identify the current branch, untracked files, modified files, deleted files and changes that are already staged.
git status
Use it regularly before staging and committing your project changes.
git add to stage changes.git commit to record staged changes.git status regularly during development.Question: Which Git command shows the current state of the working directory and staging area?