Around Go: command line · 3 MIN READ

Git daily work: inspect, branch, stage and commit

Keep working tree, staging area and committed history distinct.

Git records snapshots, not a magic backup of every unsaved editor buffer. Start in an existing local repository and inspect your changes. The sequence below makes a topic branch, stages one reviewed path and records a local commit; publishing comes in the next lesson.

01

Inspect before selecting a change

git status --short summarizes tracked and untracked paths. git diff shows unstaged tracked changes; git diff --staged shows what the next commit contains. Untracked file content is not included in ordinary git diff.

bash
git status --short
git diff -- main.go
git diff --staged
git log -5 --oneline
Read the code

Compare the two diff views. A file can have both staged and unstaged edits, and the next commit includes only the staged snapshot. -- separates options/revisions from the path main.go.

02

Put a reviewed change on a topic branch

switch -c creates and selects a new branch at the current commit. add stages the named content. Inspect the staged result before committing, rather than using add . when a repository includes unrelated experiments or local credentials.

bash
git switch -c feature/health-check
git add -- main.go
git diff --staged
git commit -m "Add health endpoint"
Read the code

Use an unused branch name and a real main.go change. The commit remains local until you push it. If a hook fails, inspect its output and rerun the necessary check rather than bypassing it automatically.

03

Unstage without discarding your edit

restore --staged changes the index back toward HEAD while leaving the working file intact. A plain restore of the working tree has a different, destructive meaning. Check both views after unstaging to make the distinction visible.

bash
git restore --staged -- main.go
git status --short
git diff -- main.go
Read the code

Use this on a staged change before committing. Your edits should now be unstaged. This is not a command to undo an existing commit; history repair and reverting a published change are different operations.

TAKE THIS WITH YOU

Review unstaged and staged diffs separately, stage intended paths and commit on a named branch. Unstaging an edit preserves it; overwriting the working tree may discard it.

Check your understanding

Which changes does git diff --staged show?

Go to the source

Progress stays in this browser. No account needed.