Hands-On: Build a Tiny Project

Updated

October 30, 2026

Hands-On: Build a Tiny Project

Build desk-api from nothing: init, two commits, a bad edit, a restore, an amend, a clean log.

 init → add/commit README → add/commit ping
      → restore an "oops" → amend the last message
      → leave .env untracked

 A ← B ← C     main     status clean

Setup

Use a throwaway directory. If ~/desk/desk-api already exists from earlier pages, either work there or pick ~/desk/desk-api-lab.

mkdir -p ~/desk/desk-api
cd ~/desk/desk-api
git init
git status

Expect On branch main and No commits yet.

Commit 1 — README

cat > README.md <<'EOF'
# desk-api

HTTP API for the desk.
EOF

git add README.md
git commit -m "Add README"
git log --oneline

One line of history.

Commit 2 — a tiny module

mkdir -p src
cat > src/ping.py <<'EOF'
def ping():
    return "ok"
EOF

cat > .gitignore <<'EOF'
__pycache__/
.env
EOF

git add src/ping.py .gitignore
git status
git commit -m "Add ping and gitignore"

Read it

git status
git log --oneline --graph --decorate
git show --stat HEAD

git show prints the last commit’s metadata and patch. --stat is the short file list.

Break it on purpose

echo "oops" >> README.md
git status
git diff
git restore README.md
git status

Clean again. The “oops” line is gone.

Stage, unstage, restage

echo "Health: GET /ping" >> README.md
git add README.md
git diff --staged
git restore --staged README.md
git diff
git add README.md
git commit -m "Document /ping"

Amend the message

That last message is vague. Replace it (still local, unpushed):

git commit --amend -m "Document the ping endpoint in README"
git log --oneline

Three commits. The amended hash is new. git status is clean.

Ignore a secret-shaped file

echo 'TOKEN=dev' > .env
git status

.env should be untracked (your .gitignore lists it). If it shows as untracked, the ignore pattern is working. If Git wants to add it, the .gitignore commit is missing — add the file and commit.

Leave .env untracked. Do not git add .env.

Done when

git status
git log --oneline
  • Status: clean, on main
  • Log: three commits (README, ping, document endpoint)
  • .env exists on disk and is untracked

You now have the loop this book’s later Git chapters assume: init, add, commit, status, log, diff, restore, amend.

Part II starts with commit anatomy and Conventional Commits. Remotes and forges wait until you can do this drill without looking at the page.