Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reset local repo to be exactly the same as remote repo

Tags:

git

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.

like image 251
James Avatar asked Apr 16 '12 07:04

James


People also ask

How do I reset my local github repository?

Find the commit hash of the commit you want to reset to with git log . Perform the local hard reset by running git reset --hard <commit-hash> .


2 Answers

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

like image 183
CharlesB Avatar answered Sep 21 '22 07:09

CharlesB


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 
like image 42
Sailesh Avatar answered Sep 22 '22 07:09

Sailesh