All commands

git reset

intermediate

Move the branch pointer and undo your staging decisions.

What it does

git reset rewinds your branch to an older commit. Depending on the mode it also resets the index (mixed), the index AND working tree (hard), or neither (soft). It's the power tool for 'I went too far' — and, unlike a delete, it never touches your reflog, so it can always be undone.

9a2f1c0init project4b7c2a5add componentsHEADmain74d3b9ffeat: dark modestale 74d3b9f

--soft/mixed/hard pick how far back the branch, index and worktree go

Watch it — press play

A narrated, step-by-step walkthrough that shows how to do it — not just theory. It adapts to the learner mode you picked in the top bar.

1 / 3

Step 1

Too far, too fast

A bad commit sits at the tip of your branch. You want the branch pointer to slide back over it.

git reset --hard HEAD~1
9a2f1c0init project4b7c2a5add componentsc86d9eestyle layout74d3b9foops: broken buildmainHEAD

The oops commit is on top

Under the hood

1

Reset moves the branch ref — not HEADs file

Reset takes the commit you're pointing at and rewrites refs/heads/<you> to an older hash. HEAD itself keeps pointing at the same branch file; the branch just moves backward.

git reset --soft HEAD~2   # branch now at old commit
main:  9a2f1c0 ← 4b7c2a5 ← 74d3b9f(moved away)
2

The three modes are all about the index

Mixed (default) resets the branch AND the index. Soft moves only the branch (index stays staged). Hard moves branch, index AND rewrites the working tree. The mode picks which of the three stores (branch / index / worktree) gets rolled back.

3

The old commits aren't deleted

Nothing is removed from objects/. Unlinked commits simply become unreachable — and the reflog still lists them. `git reset --hard HEAD@{1}` brings you straight back.

4

Never reset shared history

Because reset rewinds the branch pointer, anyone who cloned that branch will see it vanish and require force-push reconciliation. Use git revert instead on shared branches.

Aliases the pros type

Memorize the git reset concept, then let one of these shortcuts make it instant. Aliases are real git config keys — add one with:

git config --global alias.st # → git reset
AliasWhy people use it
g res

Mixed reset — unstage but keep files.

g ressh

Undo the last commit, keep it staged.

g reshard

Discard ALL local uncommitted changes.

Command anatomy

git reset [--soft|--mixed|--hard] <commit>
--soft

Move the branch only; keep the index staged.

--mixed

Default: move branch + unstage the index; keep files.

--hard

Move branch, wipe the index AND the working tree.

<path>

Reset just that path in the index from another revision.

When to reach for it

You committed to the wrong branch: reset --soft to fix the pile and re-commit elsewhere.

Unstage everything: git reset (mixed) — the index-dance escape hatch.

Full revert of local-only mess: git reset --hard HEAD.

Pro tip

Training rule for the three modes: SOFT forgets the commit, MIXED also forgets the staging, HARD also forgets the files. Memorize as 'the deeper the reset, the more you lose' — and that reflog can always rebuild it within 90 days.

Go deeper with