I have downloaded a repository with
git clone <address>
i have made some modification and have edited some files, now i want to discard everything and just be sure that what i have on the disk is nothing else than the original remote version of the codebase: what is the right command ?
Here is the long explanation so that you understand what is going on:
Assuming the remote is called
originWhat this does is:
(Optional if git status says no modified files) Discard any modified files on the disk (that’s why
reset --hard)Checkout the remote master branch (note: you will be in a “detatched head” state)
Delete the local
masterbranch (throwing away all your local changes)Call the current head as the new
masterbranchNow you probably want to do something slightly different… i.e. don’t throw away your changes , just put them on another named branch… after all you never know when you’ll need them again
That saves your current changes in a new local branch called
my-silly-changesand then removes the old local branch calledmasterand finally recreates it from the remote head.And here is the explanation for people who think they know what they are doing:
The single command:
Will discard any local changes and re-point the current branch to the most recently fetched state of
origin/master. This has the exact same effect as the four commands at the start of this answer, but without looking behind the curtain