Reset local git branch to match the remote branch

June 7, 2022  ‐ 1 min read

Resetting the state of one of your local branches to a remote branch can be done with just two commands. Some caution in advance, this does contain a hard reset in which you can possibly lose your local changes. If you have changes that shouldn't get lost you can stash them or keep them in another branch.

The first step is to make sure we are up-to-date with the refs of the remote. We do this by doing a git fetch. Second, we do a hard reset of our current branch to the state of the remote. Assuming our remote is called origin and we wish to reset to a branch called main this looks like the following.

$ git fetch origin
$ git reset --hard origin/main