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
git checkout develop
Reset to Origin Branch
Now we can reset to our origin branch.
git reset --hard origin/develop
This will replace whichever branch you are currently on with the contents of
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! 😭
🚨 Want to make friends and learn from peers? You can join our free web developer community here. 🎉