When working with Git, one question appears again and again:
What is happening in my repository right now?
You may have created a new file, modified an existing program, deleted a file, or prepared some changes for a commit.
But how do you know what Git has detected?
The answer is the git status command.
git status is one of the most important and frequently used Git commands. It displays the current state of your Working Directory and Staging Area.
For beginners, git status acts like a guide. It tells you which files have changed, which files are untracked, which changes are staged, and what you should do next.
In this article, we will understand the git status command in detail with practical examples and step-by-step outputs.
What is the git status Command?
The git status command displays the current state of a Git repository.
The basic syntax is:
git status
It helps you answer questions such as:
Which branch am I currently using?
Which files are untracked?
Which files have been modified?
Which files are staged?
Which files are ready to be committed?
Is my Working Directory clean?
In simple words:
git statustells you what Git currently sees in your project.
Why is git status Important?
Git does not automatically commit every change you make.
Files move through different states:
Untracked
↓
Staged
↓
Committed
↓
Modified
↓
Staged Again
↓
Committed Again
The git status command helps you identify the current state of these files.
Professional developers frequently run git status before commands such as:
git add
and:
git commit
This helps prevent accidental commits.
Creating a Repository for Practice
Let us create a simple project.
Create a folder named:
GitPractice
Open the terminal inside the folder.
Run:
git init
Git will display output similar to:
Initialized empty Git repository in D:/GitPractice/.git/
Now run:
git status
You may see:
On branch main
No commits yet
nothing to commit (create/copy files and use "git add" to track)
Let us understand this output.
Understanding the First git status Output
On Branch Main
On branch main
This tells you the name of your current branch.
In this example, the current branch is:
main
A branch is an independent line of development.
We will study branches in detail later in this series.
No Commits Yet
No commits yet
This means that the repository does not contain any commits.
The repository has been initialized, but no project snapshot has been created.
Nothing to Commit
nothing to commit
This means Git has not found any files or changes ready for a commit.
The repository is currently empty.
Checking an Untracked File
Now create a file:
Main.java
Add the following Java program:
public class Main
{
public static void main(String args[])
{
System.out.println("Hello Git");
}
}
Save the file.
Now run:
git status
The output will look similar to:
On branch main
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
Main.java
nothing added to commit but untracked files present
Git has detected the new file.
What Does "Untracked Files" Mean?
The following message appears:
Untracked files:
This means Git can see the file, but Git has never tracked it before.
The file exists in the Working Directory.
However, it has not been added to the Staging Area.
The current state is:
Main.java
↓
Untracked
Git also gives you a suggestion:
use "git add <file>..." to include in what will be committed
One useful feature of git status is that Git often tells you what command you can use next.
Staging the File
To prepare Main.java for a commit, run:
git add Main.java
Now run:
git status
The output changes:
On branch main
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: Main.java
Notice the message:
Changes to be committed:
This means the file is now in the Staging Area.
The file state is:
Untracked
↓
git add
↓
Staged
The file is ready for the next commit.
Understanding "Changes to Be Committed"
When Git displays:
Changes to be committed:
it means that the listed changes are currently staged.
If you run the git commit command, these changes will become part of the repository's history.
For example:
new file: Main.java
The words new file tell us that Git is preparing to save a new file in the repository.
Creating the First Commit
Now create a commit:
git commit -m "Add Main Java program"
After the commit, run:
git status
The output may be:
On branch main
nothing to commit, working tree clean
This is an important Git message.
What Does "Working Tree Clean" Mean?
The message:
nothing to commit, working tree clean
means:
There are no untracked files.
There are no modified tracked files.
There are no staged changes waiting for a commit.
In simple words:
Your current project files match the latest commit.
The repository is completely up to date.
Checking a Modified File
Now open Main.java.
Change:
System.out.println("Hello Git");
to:
System.out.println("Welcome to Git");
Save the file.
Now run:
git status
The output may look like:
On branch main
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
modified: Main.java
no changes added to commit
Git has detected that Main.java has changed.
What Does "Changes Not Staged for Commit" Mean?
The message:
Changes not staged for commit:
means that a tracked file has been modified, but the latest changes have not been added to the Staging Area.
The file state is:
Committed
↓
Edit File
↓
Modified
The changes currently exist only in the Working Directory.
To stage them, run:
git add Main.java
Staging a Modified File
Run:
git add Main.java
Then:
git status
The output changes to:
Changes to be committed:
modified: Main.java
The file has moved from:
Modified
↓
git add
↓
Staged
The latest changes are now ready for a commit.
Checking Multiple Files
Suppose your project contains:
GitPractice
│
├── Main.java
├── Student.java
└── README.md
Assume:
Main.javais modified.Student.javais staged.README.mdis untracked.
Run:
git status
Git may display:
Changes to be committed:
new file: Student.java
Changes not staged for commit:
modified: Main.java
Untracked files:
README.md
This single command gives you a complete overview of the repository.
We can understand the output as:
| File | State |
|---|---|
| Main.java | Modified |
| Student.java | Staged |
| README.md | Untracked |
This is why git status is so useful.
Understanding Git Status Messages
Let us summarize some common messages.
Untracked Files
Untracked files:
Meaning:
Git has detected new files that it has never tracked.
Changes Not Staged for Commit
Changes not staged for commit:
Meaning:
Tracked files have been modified, but the changes are not staged.
Changes to Be Committed
Changes to be committed:
Meaning:
Changes are in the Staging Area and ready for a commit.
Working Tree Clean
nothing to commit, working tree clean
Meaning:
There are no new, modified, or staged changes.
The Short Status Command
The normal git status output can become long in large projects.
Git provides a shorter version:
git status --short
You can also use:
git status -s
Example output:
M Main.java
A Student.java
?? README.md
At first, this output may look confusing.
Let us understand it.
Understanding Short Status Symbols
??
Example:
?? README.md
Meaning:
The file is untracked.
M
Example:
M Main.java
Meaning:
The file has been modified in the Working Directory.
A
Example:
A Student.java
Meaning:
The file has been added to the Staging Area.
D
Example:
D Test.java
Meaning:
The file has been deleted.
Short Status Table
| Symbol | Meaning |
|---|---|
?? | Untracked file |
M | Modified file |
A | Added/Staged file |
D | Deleted file |
R | Renamed file |
These symbols help developers quickly understand repository changes.
A Complete Practical Example
Let us understand the complete process.
Step 1: Initialize Repository
git init
Check status:
git status
Output:
nothing to commit
Step 2: Create a File
Create:
Main.java
Check status:
git status
State:
Untracked
Step 3: Stage the File
Run:
git add Main.java
Check status:
git status
State:
Staged
Step 4: Commit the File
Run:
git commit -m "Add Main program"
Check status:
git status
Output:
nothing to commit, working tree clean
Step 5: Modify the File
Edit Main.java.
Check status:
git status
State:
Modified
Step 6: Stage Again
Run:
git add Main.java
State:
Staged
Step 7: Commit Again
Run:
git commit -m "Update welcome message"
The latest changes are now permanently stored in the repository.
When Should You Use git status?
You should run git status frequently.
A good Git workflow is:
Edit Files
↓
git status
↓
git add
↓
git status
↓
git commit
↓
git status
You can use git status:
After creating files.
After modifying files.
Before staging changes.
After using
git add.Before creating a commit.
After creating a commit.
When you are confused about your repository.
A simple rule is:
When you don't know what Git is doing, run
git status.
Common Beginner Mistakes
Mistake 1: Ignoring git status
Beginners often directly run git add . and git commit.
This may accidentally include unwanted files.
Always review the repository state first.
Mistake 2: Thinking Modified Files Are Ready to Commit
A modified file is not automatically staged.
You must prepare the changes before committing them.
Mistake 3: Confusing Untracked and Modified Files
An untracked file is new to Git.
A modified file was already tracked but has changed.
Mistake 4: Not Checking Status Before Commit
Always verify which files are staged before creating a commit.
This keeps your Git history clean.
Best Practices
Run
git statusfrequently.Always check status before creating a commit.
Review untracked files carefully.
Do not blindly stage every file.
Use
git status -sfor a quick overview.Read Git's suggestions in the status output.
Git often tells you exactly what command to use next.
Summary
The git status command displays the current state of your Git repository. It shows untracked files, modified files, staged changes, and whether the Working Directory is clean.
It does not modify files or create commits. It is a safe command that simply reports information about the repository.
Understanding git status is essential because it helps you know exactly where your files are in the Git lifecycle.
Professional developers use this command constantly to avoid mistakes and maintain clean repositories.
Comments
Post a Comment