GIT & VERSION CONTROL · REFERENCE
Your Everyday Workflow
Understand exactly what gets included in a commit, using a small change to index.html.
At a glance
| Term or command | What it means | When to use it |
|---|---|---|
| git status | Shows branch and file states. | Use before and after recording changes. |
| git diff | Shows unstaged changes in tracked files. | Read what changed since the staged version. |
| git add index.html | Stages the file’s current saved content. | Select a specific file instead of accidentally including unrelated files. |
| git diff --staged | Compares staged content with the current commit. | Review what your next commit will record. |
| git commit -m "message" | Records staged changes with a message. | Commit one coherent change after checking it. |
Commands are examples, not an interactive terminal. Run them in your own learning repository after checking the prerequisites. Output, paths, commit IDs, and wording can vary. Host-specific instructions are labeled.
1. Review the saved edit
Prerequisite: finish Start Here, so index.html is already tracked. Change the heading in your editor and save. Run inside my-website. Output below is an excerpt.
Commands
git status --short
git diff
Example output
M index.html
- <h1>My first version</h1>
+ <h1>My updated website</h1>
In short status, the first column describes the index and the second describes the working tree. Here the second-column M means an unstaged modification. In a diff, minus means the old line and plus means its replacement.
2. Select and inspect the next snapshot
Stage only index.html, then inspect the selection.
Commands
git add index.html
git status --short
git diff --staged
Example output
M index.html
- <h1>My first version</h1>
+ <h1>My updated website</h1>
The M has moved to the index column. Add does not upload the file. If you edit again afterward, add again to include those later edits in this commit.
3. Record the change
The staged diff should contain only the update you intend. Test the webpage before committing.
Commands
git commit -m "Update homepage heading"
git status
Example output
[main b2c3d4e] Update homepage heading
1 file changed, 1 insertion(+), 1 deletion(-)
On branch main
nothing to commit, working tree clean
Your commit ID will differ. A useful message describes the result. “Update homepage heading” tells a future reader more than “stuff” or “changes.” This commit remains local until pushed.
What if I changed several files?
Stage related files by naming them, review the staged diff, and commit them together when they form one complete change. Use a separate commit for an unrelated correction. Plain git diff does not display a new untracked file’s content; stage it, then use git diff --staged.
git add index.html css/styles.css
git diff --staged
A commit normally records what is staged. A clean status does not prove the website works; it only reports that Git has no relevant pending file changes.
Sources and further reading
Study questions
Explain it in your own words, then open the answer.
Does git add send changes online?
No. It selects saved content in the local staging area.
What if I edit a file after staging it?
The staging area keeps the earlier selected content until you add the updated file again.
How do I review the next commit?
Use git diff --staged before committing.
Does git diff show a new untracked file?
Not normally. Add the file, then inspect its staged diff.
Does clean status mean my code has no bugs?
No. It describes Git’s file state, not software correctness.