Normally, git clone
is happy to clone empty repositories, it just prints the warning
warning: You appear to have cloned an empty repository.
Is there any way to tell git to clone only non-empty repositories? Ideally, I would prefer git clone
to simply fail (without creating a working copy) if the repository is empty.
My current solution is in three steps: (1) clone, (2) see if the clone is empty, (3) delete if it is empty. Does the job but hardly elegant (and it prints warnings that I will need to filter out). Is there a more straightforward solution?
There is not really a way to do that, but you could approximate it (somewhat poorly): set up a remote pointing to the repo you might clone, and then run git ls-remote
on that remote. (You can do this with any git repository, including a temporary empty one.) If ls-remote finds no refs, cloning that repository would have created an empty repository.
There are two major defects with this method, and one minor:
I think you might as well just clone-and-maybe-remove, really. (Or just clone and don't remove: there's nothing wrong with an empty repo. I see from a comment that you don't want them; I just don't see the reason why you don't want them. "For automation" is a purpose, but not a reason.)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.