Monday, 26 January 2026

Git: Cleaning up

Sometimes, our IDE can make a mess of things (mostly because we did something wrong, though).

And in order to fix it, sometimes we have to get rid of all unversioned files, so that we have a clean git repository and then create a new Project in our IDE.

This helps as it forces the IDE to recreate its config files from scratch.

This blog is just a small note on how to clean your git repository of all unversioned files.

A dry run would look like this:

git clean -n -x -d

A proper clean would look like this:

git clean -d -x

Options:

-n
dry run
-d
also recursively delete unversioned directories.
-x
ignore .git-ignore rules (convenient for cleaning up buildproducts and IDE config files)

Output of a dry run would look something like this:

% git clean -n -x -d
Would remove .DS_Store
Would remove .idea/
Would remove mrbear-parent/mrbear-app/target/
Would remove mrbear-stubs/.gradle/
Would remove mrbear-stubs/.kotlin/
Would remove mrbear-stubs/build/

See also "git restore" or "git reset".

References

git-clean - Remove untracked files from the working tree
https://git-scm.com/docs/git-clean

No comments:

Post a Comment