How to Reset a Local Branch to the Remote Branch in Git

Published Sep 25, 2021  ∙  Updated May 2, 2022

Suppose we made some funky changes and need to reset our local branch to the state of the remote branch.

0. Backup Our Work

Before we do anything, let’s backup our work. If we want to save our work onto another branch, we can commit our work and set it onto another branch.

git commit -a -m "Backup your work, kids"
git branch branchWithBackup

Now, our work is on branch branchWithBackup just in case we want to reference it later on. Feel free not to do this.

1. Fetch Remote Branch

Next, we should fetch the remote branch.

git fetch origin

Here, we’re assuming the remote repository is origin. If we never explicitly changed the name of the remote, it’s likely origin. If we want to check, we can use git remote to list all remote names.

2. Perform the Hard Reset

Then, we can perform the reset.

git reset --hard origin/branchName # One way to do it
git reset FETCH_HEAD --hard # Another way to do it