status Git Command Guide
The git status command displays the state of the working directory and the staging area, showing which changes have been staged, which haven’t, and which files aren’t being tracked by Git.
git status Syntax:
Section titled “git status Syntax:”git status [<options>] [--] [<pathspec>...]Output Control Options:
Section titled “Output Control Options:”| Option | Description |
|---|---|
-s, --short | Give output in short format |
--porcelain[=<version>] | Give output in machine-readable format |
-v, --verbose | Show additional information |
--column[=<options>] | Display output in columns |
--no-column | Don’t display in columns |
Status Information Options:
Section titled “Status Information Options:”| Option | Description |
|---|---|
-b, --branch | Show branch and tracking info |
--show-stash | Show stash state |
--ahead-behind | Show ahead/behind counts for branches |
-u[<mode>], --untracked-files[=<mode>] | Show untracked files |
--ignored[=<mode>] | Show ignored files |
Performance Options:
Section titled “Performance Options:”| Option | Description |
|---|---|
--ignore-submodules[=<when>] | Ignore changes to submodules |
--no-renames | Don’t detect renames (faster) |
Parameters:
Section titled “Parameters:”| Parameter | Description |
|---|---|
<pathspec> | Limit status to specific paths |
Understanding Status Output:
Section titled “Understanding Status Output:”Git Status Areas:
Section titled “Git Status Areas:”Repository State Areas:├── Working Directory: Files on disk├── Index (Staging Area): Staged changes ready for commit├── HEAD: Last commit on current branch├── Untracked Files: New files not in Git└── Ignored Files: Files excluded by .gitignore
Status Relationships:Working Directory ── git add ──► Index ── git commit ──► HEAD │ │ │ │ │ │ └──────────── git checkout ────┴──────── git reset ──────┘File Status Indicators:
Section titled “File Status Indicators:”File Status Symbols:├── ' ' = unmodified├── M = modified├── A = added├── D = deleted├── R = renamed├── C = copied├── U = updated but unmerged├── ? = untracked└── ! = ignored
Status Combinations:├── ' M' = modified in working directory├── 'M ' = staged modification├── 'MM' = modified in both working and staged├── 'A ' = newly staged file├── ' D' = deleted in working directory├── 'D ' = staged for deletion└── '??' = untracked fileStatus Output Sections:
Section titled “Status Output Sections:”Standard Status Output:├── Branch Information: Current branch and tracking status├── Staged Changes: Files staged for commit ("Changes to be committed")├── Unstaged Changes: Modified files not staged ("Changes not staged")├── Untracked Files: New files not tracked ("Untracked files")└── Suggestions: Helpful commands for next stepsBasic Status Operations:
Section titled “Basic Status Operations:”Standard Status:
Section titled “Standard Status:”# Show full statusgit status
# Show status with branch infogit status --branch
# Show status for specific pathsgit status src/ README.md
# Show status with stash infogit status --show-stashShort Format Status:
Section titled “Short Format Status:”# Short format (porcelain-like)git status --shortgit status -s
# Short format with branch infogit status --short --branch
# Short format for specific directorygit status --short docs/Porcelain Format (Scripting):
Section titled “Porcelain Format (Scripting):”# Machine-readable formatgit status --porcelain
# Porcelain v2 formatgit status --porcelain=v2
# Parse status in scriptsgit status --porcelain | while read -r status file; do case "$status" in "M ") echo "Modified: $file" ;; "A ") echo "Added: $file" ;; "D ") echo "Deleted: $file" ;; "??") echo "Untracked: $file" ;; esacdoneAdvanced Status Queries:
Section titled “Advanced Status Queries:”Untracked Files Control:
Section titled “Untracked Files Control:”# Show all untracked filesgit status --untracked-files=all
# Show only untracked files in directoriesgit status --untracked-files=normal # Default
# Don't show untracked filesgit status --untracked-files=no
# Show untracked files recursivelygit status --untracked-filesIgnored Files Display:
Section titled “Ignored Files Display:”# Show ignored filesgit status --ignored
# Show only ignored filesgit status --ignored=matching
# Show ignored files recursivelygit status --ignoredBranch and Tracking Information:
Section titled “Branch and Tracking Information:”# Show detailed branch infogit status --branch --ahead-behind
# Show branch with verbose trackinggit status -b -v
# Show branch status in short formatgit status --short --branchColumnar Output:
Section titled “Columnar Output:”# Display in columnsgit status --column
# Column optionsgit status --column=plain # No colorsgit status --column=dense # Compactgit status --column=column # Auto-columngit status --column=row # Row-basedgit status --column=auto # Auto-detectConfiguration and Best Practices:
Section titled “Configuration and Best Practices:”Git Configuration for Status:
Section titled “Git Configuration for Status:”# Configure status behaviorgit config status.showUntrackedFiles all # Show all untrackedgit config status.relativePaths true # Use relative pathsgit config status.submoduleSummary true # Show submodule status
# Configure colorsgit config color.status.branch green # Branch colorgit config color.status.added green # Added files colorgit config color.status.changed red # Changed files colorgit config color.status.untracked yellow # Untracked files color
# Configure status displaygit config status.short true # Always use short formatStatus Best Practices:
Section titled “Status Best Practices:”# Check status frequentlygit status # Before commitsgit status --short # Quick checksgit status --porcelain # For scripts
# Use status in workflowsbefore_commit() { if ! git diff --quiet; then echo "You have unstaged changes" git status --short return 1 fi}
# Check for clean working treeis_clean() { [ -z "$(git status --porcelain)" ]}
# Monitor repository statewatch_repo() { while true; do clear git status --short --branch sleep 2 done}Performance Optimization:
Section titled “Performance Optimization:”# Fast status checksgit status --porcelain # Machine readablegit status --short # Minimal outputgit status --no-renames # Skip rename detection
# Limit scope for large reposgit status -- <specific-path> # Check specific pathsgit status --ignore-submodules # Skip submodules
# Cache status for performance# Git automatically caches status infoIntegration with Development Workflows:
Section titled “Integration with Development Workflows:”Pre-commit Status Checks:
Section titled “Pre-commit Status Checks:”#!/bin/bash# Pre-commit status validation
pre_commit_check() { echo "Pre-commit status check"
# Check for unstaged changes if ! git diff --quiet; then echo "Warning: Unstaged changes detected" git status --short echo "Stage changes with: git add <files>" fi
# Check for untracked files if git status --porcelain | grep -q "^??"; then echo "Warning: Untracked files detected" git status --short | grep "^??" echo "Add files with: git add <files>" fi
# Check for staged changes if git diff --cached --quiet; then echo "No staged changes to commit" return 1 fi
echo "Status check passed"}
pre_commit_checkCI/CD Status Validation:
Section titled “CI/CD Status Validation:”# CI/CD status validationci_status_check() { echo "CI/CD status validation"
# Ensure clean working tree if ! git diff --quiet --cached; then echo "Error: Staged changes in CI" git status exit 1 fi
# Check for uncommitted changes if ! git diff --quiet; then echo "Error: Uncommitted changes in CI" git status --short exit 1 fi
# Verify branch state current_branch=$(git rev-parse --abbrev-ref HEAD) if [ "$current_branch" = "HEAD" ]; then echo "Error: Detached HEAD state" exit 1 fi
echo "CI status validation passed"}
ci_status_checkStatus Monitoring Scripts:
Section titled “Status Monitoring Scripts:”# Repository status monitoringmonitor_status() { echo "=== Repository Status Monitor ==="
# Overall status git status --short --branch
# File counts by status echo "File counts:" git status --porcelain | awk ' BEGIN {modified=0; added=0; deleted=0; untracked=0} /^M/ {modified++} /^A/ {added++} /^D/ {deleted++} /^\?\?/ {untracked++} END { print " Modified: " modified print " Added: " added print " Deleted: " deleted print " Untracked: " untracked }'
# Recent commits echo "Recent activity:" git log --oneline -3
echo "Status monitoring complete"}
monitor_statusTroubleshooting Common Issues:
Section titled “Troubleshooting Common Issues:”Status Shows Wrong Information:
Section titled “Status Shows Wrong Information:”# Refresh status cachegit status --porcelain > /dev/null # Refresh cache
# Check file system statels -la file.txt # Check file existsstat file.txt # Check file metadata
# Reset index if corruptedgit reset --mixed HEAD # Reset staging areagit status # Check status againPerformance Issues:
Section titled “Performance Issues:”# Speed up status in large reposgit status --ignore-submodules # Skip submodulesgit status --no-renames # Skip rename detectiongit status --untracked-files=no # Skip untracked files
# Use git status alternativesgit diff --name-only # Just changed filesgit ls-files --modified # Modified tracked filesEncoding and Character Issues:
Section titled “Encoding and Character Issues:”# Handle encoding problemsexport LC_ALL=en_US.UTF-8git status
# Configure encodinggit config core.quotepath false # Don't quote UTF-8 pathsgit config gui.encoding utf-8 # GUI encoding
# Handle special charactersgit status --porcelain # Avoid display issuesSubmodule Issues:
Section titled “Submodule Issues:”# Handle submodule statusgit status # Show submodule statusgit status --ignore-submodules # Ignore submodule changesgit status --ignore-submodules=dirty # Show only dirty submodules
# Update submodules for accurate statusgit submodule update --initgit statusBranch Information Issues:
Section titled “Branch Information Issues:”# Fix branch tracking issuesgit status --branch # Show branch infogit branch -vv # Show tracking branches
# Set upstream branchgit branch --set-upstream-to=origin/main main
# Check remote statusgit remote -v # Check remotesgit fetch # Update remote infoUntracked Files Issues:
Section titled “Untracked Files Issues:”# Control untracked file displaygit status --untracked-files=all # Show all untrackedgit status --untracked-files=normal # Show in directoriesgit status --untracked-files=no # Hide untracked
# Check .gitignorecat .gitignore # Check ignore patternsgit check-ignore -v file.txt # Check why file ignoredColor and Display Issues:
Section titled “Color and Display Issues:”# Fix color issuesgit config color.status true # Enable colorsgit config color.ui true # Enable all colors
# Fix column displaygit status --no-column # Disable columnsgit status --column=plain # Plain column display
# Check terminal capabilitiesecho $TERM # Terminal typetput colors # Color supportReal-World Usage Examples:
Section titled “Real-World Usage Examples:”Development Workflow Integration:
Section titled “Development Workflow Integration:”#!/bin/bash# Development workflow with status checks
dev_workflow_status() { echo "=== Development Workflow Status ==="
# Check current branch current_branch=$(git rev-parse --abbrev-ref HEAD) echo "Current branch: $current_branch"
# Show status overview git status --short --branch
# Check for common issues issues_found=0
# Uncommitted changes if ! git diff --quiet; then echo "⚠ Uncommitted changes detected" ((issues_found++)) fi
# Unstaged changes if ! git diff --cached --quiet; then echo "⚠ Unstaged changes detected" ((issues_found++)) fi
# Untracked files if git status --porcelain | grep -q "^??"; then untracked_count=$(git status --porcelain | grep -c "^??") echo "⚠ $untracked_count untracked files" ((issues_found++)) fi
# Ahead/behind remote if git status --branch --porcelain | grep -q "\[ahead\|behind\]"; then echo "⚠ Branch is ahead/behind remote" ((issues_found++)) fi
if [ $issues_found -eq 0 ]; then echo "✓ Repository is clean" else echo "Found $issues_found issues to address" fi
echo "Workflow status check complete"}
dev_workflow_statusStatus-Based Commit Preparation:
Section titled “Status-Based Commit Preparation:”# Prepare commits based on statusprepare_commit() { echo "Preparing commit based on repository status"
# Get status information status_info=$(git status --porcelain)
if [ -z "$status_info" ]; then echo "No changes to commit" return 0 fi
# Categorize changes modified_files=$(echo "$status_info" | grep "^M" | wc -l) added_files=$(echo "$status_info" | grep "^A" | wc -l) deleted_files=$(echo "$status_info" | grep "^D" | wc -l) untracked_files=$(echo "$status_info" | grep "^??" | wc -l)
echo "Changes summary:" echo " Modified: $modified_files" echo " Added: $added_files" echo " Deleted: $deleted_files" echo " Untracked: $untracked_files"
# Interactive staging based on status echo "Select staging approach:" echo "1. Stage all changes" echo "2. Stage modified files only" echo "3. Interactive staging" echo "4. Stage by file type"
read -p "Choice (1-4): " choice
case "$choice" in 1) git add --all ;; 2) git add -u ;; 3) git add --patch ;; 4) read -p "File extension (e.g., .py, .js): " ext git add "*$ext" ;; esac
echo "Staging complete. Ready to commit."}
prepare_commitRepository Health Dashboard:
Section titled “Repository Health Dashboard:”# Repository health dashboard using statusrepo_health_dashboard() { echo "=== Repository Health Dashboard ==="
# Basic repository info echo "Repository: $(basename "$(git rev-parse --show-toplevel)")" echo "Branch: $(git rev-parse --abbrev-ref HEAD)" echo "Last commit: $(git log -1 --format='%h %s' --abbrev-commit)"
# Status overview echo "Status overview:" git status --short | head -10
# Health metrics total_files=$(git ls-files | wc -l) tracked_files=$(git ls-files | wc -l) staged_changes=$(git diff --cached --name-only | wc -l) unstaged_changes=$(git diff --name-only | wc -l) untracked_files=$(git status --porcelain | grep -c "^??")
echo "Health metrics:" echo " Total tracked files: $tracked_files" echo " Staged changes: $staged_changes" echo " Unstaged changes: $unstaged_changes" echo " Untracked files: $untracked_files"
# Health assessment health_score=100
if [ $unstaged_changes -gt 0 ]; then ((health_score -= 10)) echo "⚠ Unstaged changes detected" fi
if [ $untracked_files -gt 10 ]; then ((health_score -= 20)) echo "⚠ Many untracked files" fi
if ! git diff --quiet --cached; then ((health_score -= 5)) echo "⚠ Staged changes pending commit" fi
echo "Health score: $health_score/100"
if [ $health_score -ge 90 ]; then echo "✓ Repository is healthy" elif [ $health_score -ge 70 ]; then echo "! Repository needs attention" else echo "✗ Repository needs maintenance" fi
echo "Health dashboard complete"}
repo_health_dashboardAutomated Status Reporting:
Section titled “Automated Status Reporting:”# Automated status reporting for teamsteam_status_report() { local report_file="team-status-$(date +%Y%m%d).txt"
echo "=== Team Status Report $(date) ===" > "$report_file" echo "" >> "$report_file"
# Repository status echo "Repository Status:" >> "$report_file" git status --short --branch >> "$report_file" echo "" >> "$report_file"
# Recent activity echo "Recent Commits:" >> "$report_file" git log --oneline -5 >> "$report_file" echo "" >> "$report_file"
# Branch overview echo "Branch Overview:" >> "$report_file" git branch -v >> "$report_file" echo "" >> "$report_file"
# Issues summary echo "Issues Summary:" >> "$report_file" issues=0
if ! git diff --quiet; then echo "- Uncommitted changes present" >> "$report_file" ((issues++)) fi
if git status --porcelain | grep -q "^??"; then untracked=$(git status --porcelain | grep -c "^??") echo "- $untracked untracked files" >> "$report_file" ((issues++)) fi
if [ $issues -eq 0 ]; then echo "- No issues detected" >> "$report_file" fi
echo "" >> "$report_file" echo "Report generated: $report_file"}
team_status_reportStatus-Based Git Hooks:
Section titled “Status-Based Git Hooks:”# Git hooks using status informationcat > .git/hooks/pre-commit << 'EOF'#!/bin/bash# Pre-commit hook with status validation
echo "Pre-commit status validation"
# Check for large filesgit status --porcelain | while read -r status file; do if [ "$status" = "A " ] || [ "$status" = "M " ]; then size=$(stat -f%z "$file" 2>/dev/null || stat -c%s "$file") if [ "$size" -gt 10485760 ]; then # 10MB echo "Error: Large file detected: $file (${size} bytes)" echo "Consider using Git LFS for large files" exit 1 fi fidone
# Check for debug statementsif git diff --cached | grep -q "console\.log\|print(\|debugger"; then echo "Warning: Debug statements detected in staged changes" echo "Remove debug statements before committing" exit 1fi
# Check commit message if providedif [ -n "$2" ]; then commit_msg="$2" if [ ${#commit_msg} -lt 10 ]; then echo "Error: Commit message too short" exit 1 fifi
echo "Pre-commit validation passed"EOF
chmod +x .git/hooks/pre-commitStatus Monitoring for Long-Running Tasks:
Section titled “Status Monitoring for Long-Running Tasks:”# Monitor status during long operationsmonitor_long_operation() { local operation="$1" local pid="$2"
echo "Monitoring status during: $operation"
while kill -0 "$pid" 2>/dev/null; do echo "=== Status at $(date) ===" git status --short | head -5 echo "Operation still running (PID: $pid)" sleep 30 done
echo "Operation completed" echo "Final status:" git status --short}
# Usage examplelong_running_command &monitor_long_operation "build process" $!What’s the difference between git status and git diff?
Section titled “What’s the difference between git status and git diff?”git status shows which files are staged, modified, or untracked; git diff shows the actual content changes between working directory and staging area.
How do I see only staged changes?
Section titled “How do I see only staged changes?”Use git status —short and look for files with status in the second column, or use git diff —cached to see the actual changes.
What does “Changes not staged for commit” mean?
Section titled “What does “Changes not staged for commit” mean?”These are modified files that exist in the working directory but haven’t been added to the staging area yet.
How do I hide untracked files from status?
Section titled “How do I hide untracked files from status?”Use git status —untracked-files=no to hide untracked files, or add them to .gitignore.
What’s the difference between short and porcelain formats?
Section titled “What’s the difference between short and porcelain formats?”Both are machine-readable, but porcelain is more stable across Git versions and better for scripts.
How do I see status for a specific directory?
Section titled “How do I see status for a specific directory?”Use git status
What does “Your branch is ahead/behind” mean?
Section titled “What does “Your branch is ahead/behind” mean?”Ahead means you have local commits not pushed to remote; behind means remote has commits you haven’t pulled.
How do I see ignored files in status?
Section titled “How do I see ignored files in status?”Use git status —ignored to show files that are ignored by .gitignore.
Can git status show submodule status?
Section titled “Can git status show submodule status?”Yes, by default it shows submodule status. Use —ignore-submodules to hide submodule information.
What’s the fastest way to check if working tree is clean?
Section titled “What’s the fastest way to check if working tree is clean?”Use git status —porcelain which returns empty output for clean working tree.
How do I see status in columns?
Section titled “How do I see status in columns?”Use git status —column to display status information in columns.
Can git status detect renames?
Section titled “Can git status detect renames?”Yes, it can detect renamed files. Use —no-renames to disable rename detection for performance.
How do I see branch tracking information?
Section titled “How do I see branch tracking information?”Use git status —branch or -b to show current branch and tracking information.
What’s the difference between —ignored and —ignored=matching?
Section titled “What’s the difference between —ignored and —ignored=matching?”—ignored shows all ignored files; —ignored=matching shows only ignored files that match patterns.
Can git status show stash information?
Section titled “Can git status show stash information?”Yes, use git status —show-stash to include information about stashed changes.
How do I see ahead/behind counts?
Section titled “How do I see ahead/behind counts?”Use git status —ahead-behind to show how many commits ahead or behind the tracking branch.
What’s the —verbose option for?
Section titled “What’s the —verbose option for?”—verbose shows additional information like the commit the branch is tracking.
Can git status work with pathspecs?
Section titled “Can git status work with pathspecs?”Yes, you can limit status to specific paths: git status
How do I see status without colors?
Section titled “How do I see status without colors?”Use git config color.status false or redirect output to disable colors.
What’s the performance impact of git status?
Section titled “What’s the performance impact of git status?”Generally fast, but can be slow in large repos with many untracked files. Use —untracked-files=no to speed it up.
Can git status show remote branch status?
Section titled “Can git status show remote branch status?”Yes, it shows ahead/behind information for tracking branches.
How do I refresh status cache?
Section titled “How do I refresh status cache?”Git automatically manages status cache, but you can force refresh by running git status.
Can git status detect file permission changes?
Section titled “Can git status detect file permission changes?”Yes, it shows files with changed permissions as modified.
How do I see status in a specific format?
Section titled “How do I see status in a specific format?”Use —porcelain for machine-readable format, or —short for human-readable compact format.
Applications of the git status command
Section titled “Applications of the git status command”- Repository Monitoring: Checking current state before operations
- Workflow Management: Understanding what needs to be staged/committed
- Script Integration: Machine-readable output for automation
- Code Review Preparation: Ensuring clean state for reviews
- Debugging: Identifying unexpected repository state
- Team Coordination: Sharing repository status with team members
- CI/CD Integration: Validating repository state in pipelines
- Development Hygiene: Maintaining clean working directory