Your first repository: init, status, add, commit, log and diff step by step
In this unit you'll create a real Git repository on your own computer and practise the core loop you'll repeat thousands of times in your career: edit → status → add → commit. You'll also learn to read the history and see exactly what changed. Follow along in a terminal: Git Bash on Windows, Terminal on macOS or Linux.
Step 1: Create a project folder
cd ~ # go to your home folder
mkdir my-website # make a folder
cd my-website # enter itOn Windows, Git Bash understands these Linux-style commands. You can also create the folder in File Explorer, then right-click → "Open Git Bash here".
Step 2: Initialise the repository
git initOutput: Initialized empty Git repository in /home/you/my-website/.git/
Git created a hidden .git folder that stores all history. Never delete or edit it by hand: deleting .git deletes the whole history (your files stay, but they're no longer tracked).
Step 3: Create a file and check status
Create index.html in your editor (VS Code: code . opens the folder) with:
<!DOCTYPE html>
<html>
<head><title>My website</title></head>
<body><h1>Hello, I'm Wanjiku</h1></body>
</html>Then:
git statusOn branch main
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
index.htmlUntracked means Git sees the file but isn't recording it yet. Run git status constantly: it always tells you what state you're in and suggests next commands.
Step 4: Stage the file
git add index.html
git statusChanges to be committed:
new file: index.htmlWays to stage:
| Command | Stages |
|---|---|
git add index.html | One file |
git add css/ | A folder |
git add . | Everything changed in the current folder and below |
git add -p | Pick individual chunks of changes interactively |
To unstage (keep the change, just remove it from the next commit): git restore --staged index.html.
Step 5: Commit
git commit -m "Add home page with heading"[main (root-commit) 3f2a1bc] Add home page with heading
1 file changed, 5 insertions(+)
create mode 100644 index.html3f2a1bc is the short hash, the commit's unique ID.
Writing good commit messages
- Use the imperative mood, like a command: "Add contact form", "Fix broken menu link", "Update prices".
- Keep the first line under about 50–72 characters.
- Say what and why, not "changes" or "stuff".
- For bigger commits, run
git commitwithout-mto open an editor and write a summary line, a blank line, then details.
| Bad | Good |
|---|---|
update | Update services page with 2026 prices |
fix | Fix mobile menu not closing on tap |
asdf | Add M-Pesa payment instructions to checkout |
Step 6: Make more changes
Edit index.html to add a paragraph, and create style.css. Then:
git statusChanges not staged for commit:
modified: index.html
Untracked files:
style.cssSee exactly what changed
git diff # changes not yet staged
git diff --staged # changes staged for the next commitLines starting with - were removed; + were added. Then:
git add index.html style.css
git commit -m "Add intro paragraph and basic styles"Step 7: Read the history
git logcommit 9c8d7e6... (HEAD -> main)
Author: Wanjiku Kamau <wanjiku@example.com>
Date: Mon Sep 7 10:15:02 2026 +0300
Add intro paragraph and basic styles
commit 3f2a1bc...
Add home page with headingUseful variations:
git log --oneline # one line per commit
git log --oneline --graph --all # a drawing of branches
git log -p index.html # full changes to one file
git log --author="Wanjiku" # commits by one person
git show 3f2a1bc # details of one commitPress q to leave the log viewer.
The cycle
edit files → git status → git diff → git add → git commit → (repeat)Commit small and often: each commit should be one logical change. Small commits are easier to understand, review and undo.
Renaming and deleting tracked files
git mv style.css styles.css # rename and stage the rename
git rm old-page.html # delete and stage the deletion
git commit -m "Rename stylesheet and remove old page"If you rename or delete in your file explorer instead, git add -A stages those changes too.
What's inside .git?
ls .gitYou'll see HEAD (which branch you're on), config (repo settings), objects/ (compressed snapshots), refs/ (branch pointers). You don't need to touch these, but knowing they exist explains how Git works: branches are just tiny files pointing to commits.
Practice task
- Create a folder
recipes, rungit init. - Add
ugali.mdwith ingredients; commit "Add ugali recipe". - Add
chapati.md; commit "Add chapati recipe". - Edit
ugali.mdto add steps; viewgit diff; commit "Add ugali cooking steps". - Run
git log --oneline: you should see 3 commits.
Think about it: You edited three files: fixed a bug in login.js, changed colours in style.css, and fixed a typo in README.md. How should you commit them?Show answer
Ideally as separate commits, each one logical change: git add login.js → "Fix login failing with spaces in email", then git add style.css → "Update brand colours", then git add README.md → "Fix typo in README". Small, focused commits are easier to review and revert.
Summary
git initturns a folder into a repository (history lives in.git).git statusshows untracked, modified and staged files; use it constantly.git addstages changes;git commit -m "message"saves a snapshot.git diffshows unstaged changes;git diff --stagedshows staged ones.git log --onelineandgit showexplore history; commit small, often, with clear imperative messages.
Check yourself
Which command turns a folder into a Git repository? (two words)
Show answer
git init
Which command shows which files are modified, staged or untracked? (two words)
Show answer
git status
Which command shows commits one per line? (three words, including git)
Show answer
git log --oneline
Which command shows changes that are staged for the next commit? (three words)
Show answer
git diff --staged
What is the name of the hidden folder where Git stores history?
Show answer
.git
Is "Fix mobile menu not closing on tap" a better commit message than "fix"? (yes/no)
Show answer
yes