Sikau

Git & GitHub · Day 2 · about 25 min

Staging and committing

Choose what goes into each save point.

Pack, then post

A parcel: You put items in a box (staging), then seal and post it with a label (commit). Until it's sealed you can still swap things in and out.

Three places your work can be

  • working tree — the files as they are on disk right now.
  • staging area — changes you've chosen for the next commit (git add).
  • History — commits saved for good (git commit).
git init
echo "<h1>Momo House</h1>" > index.html
echo "body { font-family: sans-serif; }" > style.css
git status
git add index.html
git status
git commit -m "Add home page"
git add style.css
git commit -m "Add basic styles"
git log --oneline
  • git add . stages everything that changed.
  • Write messages in the present tense, saying what the commit does: "Add menu page", "Fix price typo".
  • Small commits that each do one thing are easier to understand and undo.

The rest of this lesson

  • Good commit messagesexplain
  • Why a staging area?explain
  • What's in the commit?predict
  • The commit looporder
  • Your turnwrite code
  • Badge quizquiz
  • What you learnedrecap

Continue this lesson free — run real code in your browser

Continue with Google

See all 18 lessons of Git & GitHub