2

On one of my repositories the local master is ahead of the remotes/origin/master

* - master (123)
* -
* - remotes/origin/master (456)

All my other local repos (based on the same remote repository) have the remote/origin/master at the same commit hash (123). How do I reset the local repo so the remotes/origin/master is back in sync?

xylar
  • 7,433
  • 17
  • 55
  • 100

2 Answers2

8

As Pierre pointed out you will "lose" your local modifications (if you have commited your changes they are still there as loose objects). So you might want to create a temporary branch before resetting

This will reset your local branch so it points to the same commit as the remote.

git fetch origin
git checkout -b old_master // optional 
git reset --hard origin/master
rtn
  • 127,556
  • 20
  • 111
  • 121
  • WARNING: You will lose your local modifications, if any. – Pierre Mage Mar 23 '12 at 12:48
  • ah I missed this response. I will give this a go next time, thanks – xylar Mar 23 '12 at 12:51
  • xylar: If I understood you correctly this wouldnt be the soluation for your problem. This would have resetted the local 'master' branch back to your outdated remote branch – reto Mar 23 '12 at 12:56
2

what happens if you do git fetch origin?

or if you have manually broken something with the remote branch you could always:

git remote -v # note url
git remote rm origin  
git remote add origin <url>
reto
  • 16,189
  • 7
  • 53
  • 67