Remove Untracked and Modified files from Git

Many times you do things to your site that you did not mean to. Last night I was working on my site and I made commits and pushed them to github. This morning, I used a different computer and forgot to first pull my changes to my site from last night. I just worked on a couple of files but I wanted to remove an untracked file from git and remove a file under the changes not staged for commit in git. After I did that, I could pull my site from github and get my changes from last night and then rework on these files. It was early in the process today so I won’t have to redo too much work. If you find yourself in a similar situation, here’s how to:

Remove local untracked files from git:
$ git clean -f
Use with caution: once it’s gone… it’s gone

Remove changes not staged for commit in git:
$ git stash save --keep-index

Leave a Reply

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