Skip to main content
  1. Posts/

Using git clean to remove subdirectories containing git repositories

·97 words·1 min·

I had a peculiar situation today where I cloned a repository into a directory which was inside another repository. Here’s what I was doing:

$ git clone git://gitserver/repo1.git repo1
$ cd repo1
$ git clone git://gitserver/repo2.git repo2
$ git clean -fxd
Removing repo2/
$ ls -d repo2

The second repository existed even after a git clean -fxd. I stumbled upon a GitHub page within the capistrano project that explained the problem - an extra -f was required:

$ git clean -ffxd
Removing repo2/
$ ls -d repo2
ls: cannot access repo2: No such file or directory