Skip to main content

What does the git reset command do?

git reset changes the state of the repository by moving the branch pointer (HEAD) and, depending on the mode, updating the staging area and the working tree.


Main purpose

git reset is used for:

  • undoing commits
  • rolling a branch back to a previous commit
  • changing the state of the staging area
  • (in hard mode) fully removing changes

How git reset works

The command always:

  • moves the current branch pointer to the specified commit

Additionally, depending on the mode, it can:

  • update the staging area
  • update the working directory

git reset modes

--soft

bash
git reset --soft HEAD~1
  • undoes the commit
  • the changes stay in the staging area
  • the working files do not change

--mixed (default)

bash
git reset HEAD~1
  • undoes the commit
  • the staging area is cleared
  • the changes stay in the working directory

--hard

bash
git reset --hard HEAD~1
  • undoes the commit
  • clears the staging area
  • removes the changes from the working directory leads to data loss

What git reset does NOT do

  • it does not create new commits
  • it is not intended for public branches

Important rule

git reset rewrites history. Safe to use only for local, unpublished commits.


Key phrasing for an interview

git reset moves the branch pointer to another commit and, depending on the mode, updates the staging area and the working tree, thereby undoing commits and changing the history.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.