Skip to content

The daily loop

Last updated:

Terminal window
git clone git@codebahn.net:acme/app.git
cd app
Terminal window
git status
Terminal window
git diff

git status lists which files changed. git diff shows the changed lines.

Terminal window
git add README.md
git commit -m "Explain how to run the app"

The message is for whoever reads the history next year, which may be you. Five rules cover almost everything:

  • Write the subject as an instruction: “Explain how to run the app”, not “Explained” or “Explains”.
  • Keep the subject under 50 characters, start it with a capital letter, and leave off the period.
  • Put a blank line after the subject.
  • Use the body to say why, and anything a reader would not guess from the change itself. Wrap it at 72 characters.
  • Commit one change at a time, so the subject can be honest.

A second -m adds the body:

Terminal window
git commit -m "Reject empty usernames" -m "The form let blank names through and created accounts nobody could use."

In the history it reads like this:

Reject empty usernames
The form let blank names through and created accounts nobody could use.

Some teams prefix the subject with a type, fix: or feat:, so tools can build changelogs and version numbers from the history. That convention is Conventional Commits. If your team uses it, follow it; the rules above still apply to the rest of the line. The Pro Git commit guidelines explain the reasoning.

Terminal window
git push
Terminal window
git pull

While you worked, a teammate pushed a change of their own. git pull fetches it and merges it into your branch.

Terminal window
git log --oneline -5

Each line is one commit: a short hash and its subject.

Git basics is licensed under CC BY 4.0: copy it, adapt it, keep the credit.