142 words
1 minute
Reset a Git Repo to a Pristine State

Every once in a while I run into an issue where I need to reset a repo to a specific branch and delete all files that are not tracked in the repo. Normally when this need arises, I delete the repo on my file system and then clone it again. This is a nice simple one liner that will allow you to reset all files and changes to the current branch that you have checked out

Windows Powershell

git reset --hard; git clean -fdx

Linux and Mac

git reset --hard && git clean -fdx

git reset --hard - resets all files that ARE tracked in the repo. This command leaves untracked files alone

git clean -fdx - f is force, d cleans all files and directories and x includes all untracked files

Combining this two commands will reset your repo to match the same exact head stored in origin

Reset a Git Repo to a Pristine State
https://edwardbeazer.com/posts/reset-a-git-repo-to-a-pristine-state/
Author
Edward Beazer
Published at
2021-11-28