Fundamentals 8 min read

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.

ITPUB
ITPUB
ITPUB
Master Git Basics: 3 Steps, 4 Areas, and How to Undo Mistakes

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 --hard

Staged 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/master

Pushed 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 -f

Summary

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.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Gitcommand-lineVersion ControldiffUNDOreset
ITPUB
Written by

ITPUB

Official ITPUB account sharing technical insights, community news, and exciting events.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.