Reading git status
While working on a Git project, files can exist in different states.
Some files may be:
- Newly created and still untracked.
- Modified but not staged.
- Staged and ready for the next commit.
- Unchanged and matching the latest commit.
The command:
git statusgives us a summary of the repository’s current state.
It answers questions such as:
- Which branch am I currently on?
- Which changes are staged for the next commit?
- Which tracked files have unstaged modifications?
- Which new files are still untracked?
- Is the Working Tree clean?
git status is a read-only command. It reports information but does not modify,
stage, commit, or delete anything.
Practical example
Section titled “Practical example”Suppose our project contains these three files:
auth.jsREADME.mdnotes.txtTheir current states are:
auth.jsis a new file that was added to the Staging Area.README.mdis already tracked but has been modified without runninggit addagain.notes.txtis a new file that Git has never tracked.
Running:
git statusmay display:
On branch main
Changes to be committed: new file: auth.js
Changes not staged for commit: modified: README.md
Untracked files: notes.txtStaged
- Status section
- Changes to be committed
- Example
- new file: auth.js
Unstaged
- Status section
- Changes not staged for commit
- Example
- modified: README.md
Untracked
- Status section
- Untracked files
- Example
- notes.txt
Clean
- Status output
- nothing to commit, working tree clean
- Meaning
- No staged, unstaged, or untracked changes to report
On branch main
Section titled “On branch main”On branch mainThis line tells us that the currently checked-out branch is main. It simply
identifies the branch we are currently working on.
Changes to be committed
Section titled “Changes to be committed”Changes to be committed: new file: auth.jsThis section lists changes currently stored in the Staging Area.
They are prepared to enter the next commit if we run git commit.
In this example, auth.js is a new file whose current version has already been
staged.
A beginner-friendly meaning is:
These are the changes currently selected for the next snapshot.
Changes not staged for commit
Section titled “Changes not staged for commit”Changes not staged for commit: modified: README.mdThis section lists tracked files that were modified in the Working Tree, but whose latest modifications have not been added to the Staging Area.
In this example, Git already tracks README.md, but the current modification is
available only in the Working Tree.
A beginner-friendly meaning is:
Git knows this file, but its latest change has not been selected for the next snapshot.
Untracked files
Section titled “Untracked files”Untracked files: notes.txtThis section lists new files that Git can see in the Working Tree but has never started tracking.
The file exists on disk, but it is not currently included in the Staging Area or repository history.
A beginner-friendly meaning is:
The file exists, but Git has not been asked to include it yet.
Do not say that Git cannot see the file. Git can see it and reports it as untracked.
One file can appear in two sections
Section titled “One file can appear in two sections”A single file can have both staged and unstaged changes at the same time.
For example:
- Create
auth.js. - Stage its current version:
git add auth.js- Edit
auth.jsagain without runninggit adda second time. - Run:
git statusGit may display:
Changes to be committed: new file: auth.js
Changes not staged for commit: modified: auth.jsThis is not a contradiction.
It means Git currently knows about two versions of the file:
- The version captured earlier by
git addis in the Staging Area. - The newer modification exists only in the Working Tree.
The second edit was not staged automatically.
To include the newest version in the next commit, we would need to run:
git add auth.jsagain.
This reinforces an important rule:
git addstages the file’s contents as they exist at the moment the command is executed. Later modifications remain unstaged untilgit addis executed again.
Clean Working Tree
Section titled “Clean Working Tree”If the Working Tree, Staging Area, and latest commit all match, git status
displays:
nothing to commit, working tree cleanThis means:
- There are no staged differences waiting for a commit.
- There are no unstaged modifications.
- There are no untracked files that Git needs to report.
It does not mean that the project contains no files. It means there are no currently reported changes.
Interview question: What is the difference between git status and git diff?
Section titled “Interview question: What is the difference between git status and git diff?”Short interview answer
Section titled “Short interview answer”
git statussummarizes the state of the repository and tells us which files are staged, unstaged, or untracked. The defaultgit diffshows the actual line-by-line differences between the Working Tree and the Staging Area.
Detailed comparison
Section titled “Detailed comparison”git status |
git diff |
|---|---|
| Provides a summary of file states. | Displays the actual content differences. |
| Lists filenames and categories. | Displays changed lines inside tracked files. |
| Reports staged changes. | The default command does not show staged changes. |
| Reports unstaged tracked changes. | Shows unstaged changes line by line. |
| Reports untracked filenames. | Normally does not show the contents of untracked files. |
| Does not show exactly which lines changed. | Shows added, removed, and unchanged context lines. |
| Does not modify anything. | Does not modify anything. |
How git status understands the state
Section titled “How git status understands the state”git status summarizes information from both important comparisons:
- Working Tree ↔ Staging Area: identifies unstaged modifications.
- Staging Area ↔ HEAD: identifies changes prepared for the next commit.
- It also reports new files that are not tracked in the Index.
By contrast, the default:
git difffocuses on one comparison:
Working Tree ↔ Staging AreaIt displays the actual unstaged differences line by line.
To inspect the actual differences between the Staging Area and HEAD, the
learner can use the command explained in the next lesson:
git diff --stagedEnglish summary
Section titled “English summary”git statusShows where every reported change currently stands.
git diffShows what changed line by line between the Working Tree and Staging Area.