Last Updated: March 02, 2016
· atheken

Clean up a messy git repo!

Have a git repo with a bunch of junk you want to clean up? Want to get back to a pristine checkout state?

This protip is for you!

1) git clean cleans up "junk" files/directories:

git clean -xfd

(-f to clean up files, -x to clean up ignored files, and -d to clean up directories.)

2) git checkout to get your files back to their committed state:

git checkout -- .

Run this from the root of your repo (note the . in the above command, this means "current directory", but you can use any path you need as appropriate.

Say Thanks

2 Responses
Add your response


Thanks, this really helps to clean out extra Gedit backup files that can clog a git directory.

over 1 year ago ·
Profile pic sq

I would suggest adding --dry-run first to see what is being cleaned before actually doing it. It shouldn't be an issue because all the files you are cleaning are either untracked or ignored by git, but it's just good practice.

over 1 year ago ·
Filed Under