Git: Reset a local branch from origin

NicolasBrondinBernard

Author
@NicolasBrondinBernard

The answer to your query: "git how to reset local branch to remote" !

Article published on 24/11/2021, last updated on 10/08/2026

Sometimes, after an unfortunate merge or a pull from the wrong branch, you end up in an inconsistent state, or at least an unwanted one.

Most of the time, you can go back a few commits and fix the version of your current branch.

I explain the process in this article about git reset and git revert.

But sometimes, you don't simply want to undo a commit, but rather fully resynchronize with the current state of your branch on the remote repository (remote).

To do this, nothing could be simpler: just use the git reset command, but instead of specifying a commit hash, this time we're going to point to a remote branch, like this:

git reset --hard origin/[branch_name]

In the example above, "origin" refers to the name given to the remote repository (remote), and "branch_name" corresponds to the name of the branch you want to sync with.

Be careful, the "--hard" option means that all your local changes (whether committed or not) will be lost with no way to go back!


Frederic Audet sur Unsplash

Finished reading this article?
Our newsletter

No spam. Only free content, news, and ever more resources to level up your skills!

Join +1500 developers

Comments (0)

to leave a comment

No comments yet