Git Notes
Learn git status command to monitor repository state, track changes, understand file statuses, and keep track of uncommitted work for effective version control.
git status shows the state of your working directory and staging area. Use it constantly to understand what changed and what will be committed.
Basic Usage
git status
# Output:
# On branch main
# Changes to be committed:
# new file: README.md
#
# Changes not staged for commit:
# modified: index.html
#
# Untracked files:
# .DS_Store
# config.envUnderstanding Output
File Status Categories
Short Status Format
git status -s
# or
git status --short
# Output:
# M index.html (modified, not staged)
# A README.md (added, staged)
# D old-file.js (deleted, staged)
# ?? config.env (untracked)Detailed Example
git status
# On branch main
# Your branch is ahead of 'origin/main' by 2 commits.
#
# Changes to be committed:
# new file: app.js
# modified: package.json
#
# Changes not staged for commit:
# modified: config.js
#
# Untracked files:
# .env
# build/Workflow with Status
Common Scenarios
Working tree clean:
$ git status
# On branch main
# nothing to commit, working tree clean
# ✓ All changes committedUntracked files:
$ git status
# Untracked files:
# node_modules/
# .env
# Add to .gitignore to hideAhead of remote:
$ git status
# Your branch is ahead of 'origin/main' by 3 commits
# Use: git pushBehind remote:
$ git status
# Your branch is behind 'origin/main' by 5 commits
# Use: git pullTips
- Run frequently to stay aware
- Before committing: verify status
- Before pushing: check status
- Untracked files won't be committed
- Red = not committed, Green = will be committed
Interview Q&A
Q1: What information does git status provide?
A: Current branch name, staged changes (ready to commit), unstaged changes (need git add), untracked files, and relationship to remote (ahead/behind). Tells you exactly what's different from last commit and what will be included in next commit.
Q2: Difference between staged and unstaged changes?
A: Staged changes (green text) are marked for next commit via git add. Unstaged changes (red text) are modified but not staged. Only staged changes go into commits. Use git diff to see unstaged, git diff --staged to see staged.
Q3: What does "working tree clean" mean?
A: All changes have been committed. No untracked files, no modified files. Repository matches last commit exactly. You're caught up with local work.
Q4: What should you do with untracked files shown in status?
A: Either: (1) Stage and commit if they should be tracked, or (2) Add to .gitignore if they shouldn't be tracked (build files, env files, etc). Without action, they'll keep appearing in status output.
Q5: How often should you use git status?
A: Constantly! Beginner habit: run after each change. Professional habit: automatic from editor integrations. Status is free, safe, and informative. Before committing, before pushing, when confused—always run status first.
Advanced Git Status Scenarios
Understanding git status output in complex situations helps you navigate real-world workflows confidently.
Merge Conflicts: During a merge conflict, git status shows files marked as "both modified" under an "Unmerged paths" section. These files need manual conflict resolution before you can continue the merge. After resolving conflicts, git add the file to mark it as resolved.
$ git status
On branch main
You have unmerged paths.
(fix conflicts and run "git commit")
Unmerged paths:
(use "git add <file>..." to mark resolution)
both modified: src/utils.jsInteractive Rebase: During an interactive rebase, status shows which step you're on and what state the rebase is in:
$ git status
interactive rebase in progress; onto abc1234
Last command done (1 command done):
pick def5678 Add login feature
Next command to do (2 remaining commands):
pick ghi9012 Fix validation bugDetached HEAD: When you checkout a specific commit (not a branch), status warns you about the detached HEAD state:
$ git status
HEAD detached at abc1234
nothing to commit, working tree cleanIntegrating Git Status Into Your Workflow
Editor Integration: Modern editors (VS Code, IntelliJ, Vim with fugitive) show git status inline — modified files appear with indicators in the file explorer, and changed lines are highlighted in the gutter. This gives you real-time awareness without switching to the terminal.
Shell Prompt: Configure your shell prompt to display the current branch and dirty state. Tools like oh-my-zsh, starship, or bash-git-prompt show branch name, ahead/behind counts, and dirty indicators directly in your terminal prompt. This means you always know your repository state at a glance.
Pre-commit Hooks: Use git status in pre-commit hooks to verify that only intended files are being committed. This prevents accidentally committing temporary files, environment configs, or sensitive data.
Aliases for Common Patterns: Many developers create shorter aliases for status variants they use frequently:
git config --global alias.st status
git config --global alias.ss "status -s"Exam Focus
Revise definitions, diagrams, examples, and short-answer points for Git Status - Check Repository State.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Git & GitHub topic.
Search Terms
git-github, git & github, git, github, basics, status, git status - check repository state
Related Git & GitHub Topics