This delete shouldn't be necessary. You only created an empty ".git" directory. That is not a valid Git repository. Because you have the setMustExist(true) on the RepositoryBuilder, the build() should fail and zeroid is what would be returned, even though the directory exists and is empty.