Code / Command Line & Git / Unit 3: Git basics: save every version

Your first commits आपके पहले commits

Lesson 7 of 12 · about 16 minutes · The staging area: git add, git commit -m and git log --oneline.

⚡ 0 XP

Step 1 of 3

add, then commit

Add menua1f3Add prices7c2eFix typo9b04HEAD→main

Saving in git is a two-step dance, like a photo studio:

  1. git add index.html — invite the file onto the stage (the staging area). Only staged files will be in the photo.
  2. git commit -m "Add home page" — click! The snapshot is saved forever, with your message.

Write messages that say what you did, in a few words: "Add menu", "Fix chai price". Your future self will thank you.

git add . stages everything in the current folder at once.

🎯 Challenge: Commit the home page +15 XP

You are inside the chai-site repo, and index.html is waiting (untracked). Run git status, stage it with git add index.html, then commit with a message that includes home page, for example git commit -m "Add home page". Finish with a clean status.

Try twice to unlock the solution (0/2)

terminalCtrl ⏎

A safe practice terminal. Type a command and press Enter. Type help to list commands. Tab completes names, ↑ recalls the last command.

Files · ~ = /home/asha
  • chai-site/ ← you are here
  • index.htmlU
Git timeline

Repository ready — no commits yet. (main)

Checklist

Press Run to check your code.

  • index.html is committed
  • The message mentions the home page
  • Working tree is clean
Lesson notes (text version)

1. add, then commit

Saving in git is a two-step dance, like a photo studio:

  1. git add index.html — invite the file onto the stage (the staging area). Only staged files will be in the photo.
  2. git commit -m "Add home page" — click! The snapshot is saved forever, with your message.

Write messages that say what you did, in a few words: "Add menu", "Fix chai price". Your future self will thank you.

git add . stages everything in the current folder at once.

Challenge: Commit the home page

You are inside the chai-site repo, and index.html is waiting (untracked). Run git status, stage it with git add index.html, then commit with a message that includes home page, for example git commit -m "Add home page". Finish with a clean status.

2. Choose what goes in

Why have a staging area at all? Because you choose exactly what goes into each snapshot. Your half-written notes.txt can wait while the finished about.html gets committed.

git status shows staged files under Changes to be committed, and new files git is not tracking yet under Untracked files.

Challenge: Stage just the about page

Two new files appeared: about.html (ready) and notes.txt (your private to-do list). Stage only about.html with git add about.html — do not commit yet — and run git status to see it under "Changes to be committed".

3. git log: your project diary

Every commit gets a short id, like 3f2a9c1. git log lists all commits, newest first. git log --oneline shows one neat line per commit — perfect for a quick look.

The label HEAD -> main shows where you are right now: on branch main, at its newest commit.

                git log
git log --oneline
              

Challenge: Add the menu, check the diary

The repo already has one commit. Create menu.txt containing Masala chai ₹10, commit it with the message Add menu, then run git log --oneline to see both commits.

Search by task, format or tool name.