Reset a muddled up git local repo

This looks childs play, but often I have heard people wondering how to reset their git local repo once they find they have screwed it enough. This can happen usually due to branches diverging or a badly executed command, or even altering some wanted files.

* To reset the entire repo to the remote branch master:

git stash
git checkout master .
git checkout master
git fetch --all
git pull origin master
git reset --hard origin/master
git rebase origin/master

even the same would work without these entire commands, but given all of these, you will have your git repo back to normal and the HEAD pointer pointing to the topmost master commit.

* To reset a single file foo/bar.php with the remote master:

git checkout master foo/bar.php

* If you were in between some rebase, and you need to cancel the same, and get back

rm -fr .git/rebase-apply

Yay! Hope it helps someone.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s