# Git: How to Reset a Local Branch to Remote State

> Use git fetch and git reset --hard origin/main to sync a local branch to its remote state, with a backup branch to preserve uncommitted work first

**URL:** https://sentry.io/answers/reset-a-local-branch-to-remote-state-in-git/

---

## The Problem

How do I reset the state of a branch in a local Git repository to that of a remote branch?

## The Solution

There are two commands you can use to achieve this. First, download all remote branches with `git fetch`:

```sh
git fetch origin # <-- name of remote, change if not origin
```

Second, use [`git reset`](https://git-scm.com/docs/git-reset) to sync the local branch with the remote branch:

```sh
git reset --hard origin/main
```

This process will destroy any uncommitted work, as well as any unpushed commits, so caution is advised. Consider making a backup of the local state on a separate branch, before running `git reset`:

```sh
git commit -a -m "Backup of local work"
git branch local-work
```

## Further Reading

If you're looking to build better habits as a developer, take a look at the following article:

- [11 Habits of Highly Effective Developers](https://syntax.fm/show/778/11-habits-of-highly-effective-developers)

---

*Source: [sentry.io/answers/reset-a-local-branch-to-remote-state-in-git/](https://sentry.io/answers/reset-a-local-branch-to-remote-state-in-git/)*
