Manuals / Git & GitHub / Ch 2

A · DailyBeginner35 min read

2. Daily loop: status, diff, add, commit

Git & GitHub · 48 pages source format

Working tree → staging (index) → local history → remote. status and diff before every commit.

What you'll learn

  • Working tree vs staging vs history
  • git status / diff
  • git add / commit
  • Commit messages

Three trees

Working directory (edited files), staging area (git add), repository (git commit). status shows all three.

git status
git diff
git add README.md
git diff --staged
git commit -m "docs: explain three trees"
git log --oneline -5

Do this now

Edit README. status. diff. add. diff --staged. commit. log --oneline.

Clear?

Commit messages

Imperative subject: "Add login form" not "Added". Body explains why. Conventional commits help: feat:, fix:, docs:.

Do this now

Make 3 commits with clear messages on git-practice.

Clear?

git add patterns

git add file, git add -p (patch — choose hunks), git add . (careful — review status first).

Do this now

Use git add -p once to stage part of a file.

Pro tip. Never commit secrets — .env belongs in .gitignore.

Clear?

Checklist