Reputation: 7864
I sometimes screw up my local git repo so badly that I need to just wipe it out and start again from the latest commit on remote
. Is there a correct way to do this with git, or should I just delete the local repo and pull
again? I tried the answer to this post, but my local repo was still detached from HEAD
.
Here's one example to prevent anyone from asking why I want to do this instead of fixing my mistake. I somehow ended up with a detached HEAD
, and other SO posts indicate it's a PITA to fix. My latest commit on remote
is fine, I've only changed one file, so I saved my changes and just want to start fresh instead of trying to fix the detached HEAD
.
Upvotes: 2
Views: 1986
Reputation: 3398
Assuming that by "the latest commit on remote" you mean on origin/master
, you can easily reset to that state with the following command:
git reset --hard origin/master
Or you can simply reset all local changes since the last local commit by doing:
git reset --hard
Additionally, you may want to experiment with the git clean
command to clear away any untracked local files. git clean
won't undo your changes, you need git reset --hard
for that.
Upvotes: 1