this post gives you details about exporting git in the way you mentioned .
git archive HEAD --format=zip > archive.zip
You can also archive a remote using the --remote= option. Just
be aware that this does not work with GitHub remotes, as they
encourage you to use the download button instead. With any other
remote it should work fine though, and check the manpage if you’re
having issues.
but the problem with this method is when i tried it with both github and bitbuck i got remote doesn't support protocol
error .
i just wrote code for a generic solution on my machine and its working for me . let me share it with you . you can execute shell command using php using shell_exec .
<?php
//clearing a folder named test if it exist(avoiding git errors)
shell_exec('rm -rf test');
//cloning into test folder
shell_exec('git clone https://github.com/nette/sandbox.git test');
//archiving
shell_exec('cd test && git archive HEAD --format=zip > archive.zip');
//copying to root folder
shell_exec('cp test/archive.zip archive.zip');
//removing the temp test folder we created
shell_exec('rm -rf test');
?>
shell_exec won't work if php safemode is turned on . you might require setting appropriate permissions for the script etc . but i think this an idea to start with php, for getting what you want.