Git Status Fundamentals
Understanding Git Status
Git status is a fundamental command that provides crucial information about the current state of your repository. It helps developers understand which files have been modified, staged, or are untracked.
Core Concepts
Repository States
Git tracks files in different states:
- Untracked
- Modified
- Staged
- Committed
stateDiagram-v2
[*] --> Untracked
Untracked --> Staged : git add
Staged --> Committed : git commit
Committed --> Modified : file changes
Modified --> Staged : git add
File Status Categories
Status |
Description |
Git Command |
Untracked |
New files not in repository |
- |
Modified |
Changed but not staged |
git diff |
Staged |
Files ready for commit |
git add |
Committed |
Saved in local repository |
git commit |
Basic Git Status Commands
Checking Repository Status
## Basic status check
git status
## Compact status view
git status -s
## Show branch information
git status -b
Common Status Scenarios
Scenario 1: New Repository
When you initialize a new Git repository, all files are initially untracked.
## Initialize new repository
mkdir my-project
cd my-project
git init
## Check initial status
git status
Scenario 2: File Modifications
After modifying files, git status helps identify changes.
## Modify a file
echo "New content" > README.md
## Check status
git status
Best Practices
- Always check status before committing
- Use compact view for quick insights
- Understand file states before performing operations
LabEx Tip
When learning Git, LabEx provides interactive environments to practice these fundamental commands safely and effectively.