Skip to content
beginner2 min readFree guide

Git fundamentals: working changes, staging and commits

InterviewSolutionHub learning library · Updated

On this page

Git becomes less mysterious when you distinguish the working tree, the staging area and the committed history. A commit records the staged snapshot, not every file you happened to edit.

Inspect the current state before changing it

The working tree contains the files you are editing. git status reports what is modified, staged or untracked. Read that output before switching tasks or committing. An untracked file is not automatically protected by repository history, and an ignored file may still contain important private local configuration.

Stage the change you intend to record

The staging area lets you choose the content of the next commit. After staging, later edits can leave a file partly staged and partly unstaged. Review the staged diff, not just the editor’s current text. A focused commit is easier to explain, review and investigate than unrelated changes bundled into one snapshot.

Treat history as a useful record

Use a commit message that explains the concrete change and, when helpful, its reason. A local commit and a remote push are different actions. Keep credentials, generated runtime files and private data out of the repository. If a secret was committed, deleting it in a later commit does not remove the earlier copy from history.

Worked example

In a practice repository, edit one README paragraph, inspect the diff, stage that file and inspect the staged diff. Change another sentence without staging it. git status now helps you see that the next commit and the current working file are not identical.

git status
git diff
git add README.md
git diff --cached
# Review the staged change before making a commit.

Check your understanding

Try each question before opening its explanation. These are free practice prompts; they do not use game chances.

Does git add immediately create a commit?

No. It updates the staging area. A separate commit operation records the selected snapshot in local history.

Why review the staged diff?

It shows what the next commit will contain. The working tree may also contain unstaged edits that will not be included.

What is the difference between commit and push?

A commit records a local history entry. A push attempts to send relevant history updates to a remote repository, subject to its permissions and branch rules.

Sources and further reading

These original examples explain foundational concepts. Use the official references for complete, current details and version-specific behaviour.

About this guide: AI-assisted educational content with original examples and linked primary references. Found an issue? Tell us what to improve.

Keep exploring Developer tools

All subtopics →