Tour of Git
Git Basics / Lesson 1.5

git commit — Saving Snapshots

The git commit command creates a new snapshot of your staged changes. Each commit is a permanent record in your project's history.

Anatomy of a Commit

Every commit contains:

  • A unique SHA — A hash identifier (e.g., a1b2c3d)
  • Your changes — The staged files at the time of commit
  • A message — A human-readable description
  • Author & timestamp — Who made it and when
  • Parent commit(s) — What came before (for history)

Writing Good Commit Messages

A good commit message explains why, not just what:

  • ✅ "Fix login timeout by increasing session duration"
  • ✅ "Add user profile page with avatar upload"
  • ❌ "Fix bug"
  • ❌ "Update files"

Try it!

The repository is already initialized. Make two separate commits:

  1. Create a file: echo "first" > file1.txt
  2. Stage and commit: git add file1.txt then git commit -m "Add first file"
  3. Create another file: echo "second" > file2.txt
  4. Stage and commit: git add file2.txt then git commit -m "Add second file"
  5. Check the log: git log --oneline

Watch the graph on the right update with each commit!

The -a Flag Shortcut

Once files are tracked (committed at least once), you can skip git add by using:

git commit -am "message"

This stages all modified tracked files and commits them in one step. But it won't add new untracked files.

🎯

Goal

Make two separate commits with meaningful messages

Terminal
$

No commits yet. Run `git init` and create your first commit.