Search code examples
gitgit-rm

Remove all files associated with a repository, keeping other files


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?


Solution

  • 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