Reset local repo to be exactly the same as remote repo

Git

Git Problem Overview


How do I reset my local git repo to be exactly the same as the remote repo?

I've tried:

git reset --hard HEAD^

But now git status says I have diverging commits. I basically want to just wipe anything I've got locally and get the exact remote repo on my local machine.

Git Solutions


Solution 1 - Git

git reset --hard HEAD^ will only reset your working copy to the previous (parent) commit. Instead, you want to run

git reset --hard origin/master

Assuming remote is origin and the branch you want to reset to is master

Solution 2 - Git

You could delete the current branch, and create the branch again at the remote/branchname commit

git branch -D branchname
git checkout remote/branchname
git branch branchname

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJamesView Question on Stackoverflow
Solution 1 - GitCharlesBView Answer on Stackoverflow
Solution 2 - GitSaileshView Answer on Stackoverflow