Lesson 2 of 5
Tracking Changes: Add and Commit
Starting a Repository
To let Git track a folder, move into it and run the initialisation command. This creates a hidden .git directory where Git stores all history.
git initThe Three Areas of Git
Git organises your work into three places. Understanding them is the key to using Git well.
- Working directory — your actual files as you edit them.
- Staging area — a holding zone for changes you plan to commit next.
- Repository — the permanent history of committed snapshots.
Checking Status
The git status command is your most-used command. It shows which files changed and which are staged.
git statusStaging Changes with git add
The git add command moves changes into the staging area. You choose exactly what goes into the next commit.
git add index.html # stage one file
git add styles.css app.js # stage several files
git add . # stage every change in the folderSaving a Snapshot with git commit
A commit permanently records the staged changes. Every commit needs a message describing what you did.
git commit -m "Add homepage layout and navigation"The -m option lets you write the message right on the command line.
Writing Good Commit Messages
- Write a short, clear summary of what changed and why.
- Use the present tense, for example “Fix login bug”.
- Commit small, related changes together rather than one giant commit.
Viewing History
The git log command lists past commits, newest first.
git log --onelineThe --oneline option shows each commit compactly on a single line.
Commit often. Small, frequent commits create a clear history and make it easy to find and undo the exact change that caused a problem.
Discussion
0No comments yet — be the first to leave one!