Using the attribute "size" from the API will not help as mentioned by other posters here.
An example is this repository:
https://api.github.com/repos/errfree/test
If you note, it displays the size as 48 despite being empty.
Disclaimer: This approach is a hack. It is not efficient nor officially supported by GitHub, but works good enough for me.
Basically, I download the Zip version of the repository. When the repository is empty then it will not return a zip file but provides as result an HTML page saying "This repository is empty.".
After downloading a zip file, I verify if the size is smaller than 30Kb and if this is the case, I look inside the file contents for the string "This repository is empty." to confirm that a given repository is empty.
Here is a practical example of direct zip download that on this case will display an empty page:
https://github.com/errfree/test/zipball/master/
My pseudo-code in Java:
// we might have reached an empty repository
if(fileZip.length() < 30000){
// read the contents
final String content = utils.files.readAsString(fileZip);
// is this an HTML file with the repository empty message?
if(content.contains("This repository is empty.")){
return null;
}
}
Hope this helps.