Remove all files associated with a repository, keeping other files

57 Views Asked by At

I have cloned a "dotfiles" Git repository into my home directory and I'm trying to remove all the files associated with it.

How can I safely remove all files that belong to the repository without accidentally deleting any other files from my home directory?

1

There are 1 best solutions below

0
Yuri G. On BEST ANSWER

You can use git ls-files to list the repository files and to pipe the output to rm

git ls-files | awk -F "/" '{print $1}' | sort | uniq | xargs rm -rf

After that delete the .git folder

rm -rf .git