Q7 of 40 · Git

How do you check the status of your repository and the current branch?

GitJuniorgitstatusbranchfundamentalsdaily-workflow

Short answer

Short answer: git status shows the current branch, staged changes, unstaged changes, and untracked files in one view. git branch lists local branches (current one marked with *). git log --oneline -5 shows recent commits. For a compact daily-status view, git status -s gives a two-column shorthand.

Detail

git status is the first command to run when disoriented in a repo. It tells you:

  • Which branch you're on (and whether it's ahead/behind remote)
  • Changes staged for the next commit
  • Changes in the working directory not yet staged
  • Untracked files

Branch visibility:

  • git branch — local branches
  • git branch -r — remote-tracking branches
  • git branch -a — all (local + remote)
  • git branch -v — with the latest commit SHA and message per branch

Short status (git status -s): two columns — left is staging area, right is working tree:

  • M = modified, A = added, ? = untracked, D = deleted

For scripts and CI: git status --porcelain outputs a machine-readable format that's stable across Git versions — useful for hooks that check if the working tree is clean.

// EXAMPLE

# Full status
git status

# Short format
git status -s
# M  tests/LoginTest.java   ← staged (left column)
#  M tests/UserTest.java    ← unstaged (right column)
# ?? tests/NewTest.java     ← untracked

# List branches
git branch -vv
# * feature/login   a1b2c3d [origin/feature/login: ahead 2] Add login test
#   main            e5f6789 [origin/main] Fix: user creation

# Check if working tree is clean (useful in CI / pre-commit hooks)
if git diff-index --quiet HEAD --; then
    echo "Clean — nothing to commit"
else
    echo "Uncommitted changes detected"
fi

// WHAT INTERVIEWERS LOOK FOR

Knowing git status as the daily-driver command, git branch -vv for tracking branch context, and the --porcelain flag for scripting. Candidates who reach for git log before git status often have a workflow gap.

// COMMON PITFALL

Not running git status before git add . and accidentally staging unintended files (generated reports, .env files, build outputs that should be in .gitignore).