GitYour First Commit

Your First Commit

A commit is the fundamental unit of Git — it records a snapshot of your project, who made it, when, and why. Once you can make commits with confidence, everything else (branches, merges, remotes) builds on top. This page walks you through your very first commit, end to end.

Step 0 — one-time setup

If you have never used Git on this machine, set your name and email so commits get attribution.

One-time per machine

Bash
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git config --global init.defaultBranch main
Step 1 — make a project folder and init

Bash
mkdir my-first-repo
cd my-first-repo
git init
# Initialized empty Git repository in /Users/you/my-first-repo/.git/
Step 2 — create a file

Bash
echo "# My First Repo" > README.md

You now have one file in the working directory. Git knows the file exists but is not tracking it yet.

See what Git thinks

Bash
git status
# On branch main
#
# No commits yet
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#         README.md
#
# nothing added to commit but untracked files present (use "git add" to track)
Step 3 — stage the file

Staging means: “include this version of this file in my next commit.”

Bash
git add README.md
# ─ or ─
git add .                # stage everything in the folder

Status after staging

Bash
git status
# On branch main
#
# No commits yet
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#         new file:   README.md
Step 4 — commit the snapshot

Two equivalent ways

Bash
# Short form: write the message inline with -m
git commit -m "Initial commit"

# Long form: omit -m and Git opens your editor for a message
git commit

You should see output like:

Text
[main (root-commit) 1f9ab2c] Initial commit
 1 file changed, 1 insertion(+)
 create mode 100644 README.md

That output is telling you:

  • main — you are on the main branch.

  • (root-commit) — this is the first commit (no parent).

  • 1f9ab2c — the short SHA of the new commit.

  • Initial commit — the commit message you wrote.

  • 1 file changed, 1 insertion(+) — a summary of the diff.

Success
You just made your first commit! Your project now has real history. From this point you can change anything, knowing the previous state is safe.
Step 5 — inspect the history

Bash
git log
# commit 1f9ab2c0e8b4a7d2f0c... (HEAD -> main)
# Author: Your Name <you@example.com>
# Date:   Mon Jan  1 10:00:00 2025
#
#     Initial commit

# Shorter form
git log --oneline
# 1f9ab2c (HEAD -> main) Initial commit
Step 6 — make a second commit

Bash
echo "Hello, Git!" >> README.md

git status
# modified: README.md

git diff
# +Hello, Git!

git add README.md
git commit -m "Add greeting"

git log --oneline
# d4b1e0c (HEAD -> main) Add greeting
# 1f9ab2c Initial commit

Two commits in your history. You can git diff 1f9ab2c d4b1e0c to compare them, git show d4b1e0c to see the second commit in detail, or git checkout 1f9ab2c to time-travel back.

What a good first commit message looks like
  • Use the imperative mood: “Add X”, not “Added X” or “Adding X”.

  • Keep the subject under ~50 characters.

  • If you need more detail, add a blank line and an optional longer body (use the editor form, not -m).

  • Describe what and why, not how — the diff already shows how.

A well-formed commit message

Text
Add login form validation

The previous form accepted any input, which let users submit empty
credentials. This adds client-side checks for non-empty fields and
a minimum password length of 8 characters.

Refs: #214
Shortcut: stage + commit in one step

The -a flag stages tracked files

Bash
# Stage all *tracked* files AND commit, in one command
git commit -am "Quick fix"

# Note: -a does NOT add untracked (new) files
Practice and look around
Run `git status` after every action. Run `git log --oneline` often. Make tiny commits at first. After a few sessions the rhythm of edit → add → commit becomes second nature.
Tip
Don’t be afraid to make “bad” commits while learning. Local commits cost nothing and stay on your machine. You can always amend, squash, or reset them before pushing to a shared remote.