Local Branch out of Sync? Reset a Branch to Remote

We've all been there...

And if you found this article, fear not!

We can fix the distorted branch that you've created.

Fetch and checkout the branch

In the following examples, we are using develop as an example. Swap out "develop" with whatever branch name you are trying to sync with.

First, to make sure you have all the latest changes use:

git fetch origin develop

And then make sure you are on the branch you want eg. to the develop branch:

git checkout develop

Reset to Origin Branch

Now we can reset to our origin branch.

git reset --hard origin/develop

Warning ❗️

This will replace whichever branch you are currently on with the contents of develop.

So if you're on a feature-branch, it will replace all its commits with the develop commits, so make sure you've checked out the branch you're replacing first, or else you'll lose all of your changes.

I've done it... It's not fun! 😭


Follow me on Twitter or connect on LinkedIn.

🚨 Want to make friends and learn from peers? You can join our free web developer community here. 🎉

GitGithub
Avatar for Niall Maher

Written by Niall Maher

Founder of Codú - The web developer community! I've worked in nearly every corner of technology businesses: Lead Developer, Software Architect, Product Manager, CTO, and now happily a Founder.

Loading

Fetching comments

Hey! 👋

Got something to say?

or to leave a comment.