Master Git Basics: 3 Steps, 4 Areas, and How to Undo Mistakes
This guide explains Git's core workflow—adding, committing, and pushing—covers the four Git areas (working, staging, local, remote), describes the five file states, shows how to inspect changes with diff commands, and provides step‑by‑step commands to revert modifications at any stage.
Basic Concepts
Git, created 12 years ago, is often misunderstood; this article simplifies its core workflow for beginners, assuming a single master branch.
Three‑step workflow
git add .– stage all changes. git commit -m "comment" – record staged changes in the local repository. git push – upload local commits to the remote repository.
Four Git areas
Working Area
Staging Area (Stage)
Local Repository
Remote Repository
Five file states
Unmodified (Origin)
Modified
Staged
Committed
Pushed
Inspecting Changes
Use git diff to see differences between the working area and the staging area. After git add ., git diff shows nothing because the working area matches the staging area.
To compare the staging area with the local repository, use git diff --cached. To compare the local repository with the remote, use git diff master origin/master, where master is the local branch and origin/master the remote counterpart.
Reverting Changes
Modified but not staged
Undo changes in the working area: git checkout . or
git reset --hardStaged but not committed
Return to the unmodified state: git reset or git reset --hard Both commands move changes out of the staging area; you may need git checkout . to fully revert.
Committed but not pushed
Reset the local branch to match the remote:
git reset --hard origin/masterPushed changes
If the commit has already been pushed, reset the local branch and force‑push to overwrite the remote:
git reset --hard HEAD^ git push -fSummary
The git reset --hard command, possibly combined with origin/master or HEAD^, can undo mistakes at any stage—modified, staged, committed, or pushed—making it a powerful tool for recovering from errors.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
ITPUB
Official ITPUB account sharing technical insights, community news, and exciting events.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
