learn git.
0/25 done
learn git/the basics/course 07 of 25

Your first commit

The save point is taken. One command, one message.

7 min read·3 sections·2 tasks
the key idea

git commit photographs the staged checklist into the permanent album, labelled with your message.

01The command and its one flag

With files staged, git commit -m "message" takes the photograph. Everything on the checklist goes into the album in one atomic step — either the whole photograph happens, or none of it does. The -m flag means: here is the message on this line, do not open an editor for me. Without -m, real git opens a text editor waiting for you to write one; in this simulator you just get a friendly error teaching you the flag.

The message is written for a specific reader: future-you, three months from now, staring at a list of commits trying to find when something broke. Write the label that person needs.

[bash]· add, then commit
git add notes.txt
git commit -m "add notes file"

02Decoding git's reply

Git answers with one dense line: [main (root-commit) a1b2c3d] add notes file. Left to right: you are on branch main; this is the root-commit, the very first photograph in the album; a1b2c3d is the photograph's ID — a short, unique fingerprint you can use to refer to this commit later; and the rest is your message.

Below it git prints statistics — how many files changed, lines added, lines removed — and marks like create mode 100644 notes.txt for brand-new files. You do not need to memorise any of this; just recognise that git is describing the photograph it just took.

A commit is complete

Once the commit succeeds, the checklist is empty and your project's exact state is safe forever. You could delete the files right now and git would still be able to bring them back from the album.

03Writing messages people thank you for

The message answers one question: what did this save point do? The common style is short, lowercase, present-tense, describing the change: fix crash when list is empty, add readme, start shopping list. If you cannot describe the commit in one line, that is often a sign the commit should have been two.

  • —good: fix crash when list is empty
  • —good: add readme
  • —bad: update — update what?
  • —bad: asdfgh — future-you will suffer
The test for a message

Imagine scrolling a list of fifty commits. Does yours let you skip past it, or do you have to open it to remember? If you have to open it, the message failed its one job.

>>

Practice

A repository is ready with one staged file. Take the photograph.

[practice]· a real terminal, safely simulated
practice terminal — everything here is simulated, nothing can break
type 'help' to see the commands this terminal understands
~/my-project (main) $
Your tasks0/2 done
  1. 01.Commit the staged file with any message you like.

    hint: Try: git commit -m "first save"

  2. 02.Confirm the tree is clean.

    hint: Run: git status — it should end with 'nothing to commit, working tree clean'