Git back to where you used to be

I’m still not as versed in Git as I used to be. In various situations, I find myself looking at things and saying, well, I’ve backed up my own files, I know where I used to be. How do I just wipe everything clean and start over?

Obviously there’s always delete the dir and re-clone the files. With multi-gigabyte repos over a cell connection this isn’t the best option. Here’s a list of situations and their remedies as I’ve found them. All commands are run in the main directory of your project.

I’ve got changes, but I don’t want to commit them:

#just go ahead and delete everything you know about. 
git reset --hard

I’ve got changes and new files to add, but I just want to wipe everything out:

#hey git, there's all sorts of things in here to pay attention to
git add .
#just go ahead and delete everything you know about. 
git reset --hard

My commits have diverged, but I just wanna be where the origin is, not where I am:

#just go ahead and go back to where you were. 
git reset --hard @{upstream}

I’ve got commits staged, but I just want to wipe everything out:

#wipe out the last commit. Repeat as necessary
git reset --soft "HEAD^"

Leave a Reply

Your email address will not be published. Required fields are marked *