I'm developing a Github app that needs to be able to clone GitHub repositories whenever a push event occurs.
I've successfully set everything up including the server and can clone repositories using using access tokens. However, I'm having some trouble with repositories that have submodules.
I find that using git clone --recurse-submodules https://x-access-token:<token>@github.com/owner/repo.git
doesn't work if repo.git
has submodules configured with SSH. Is there an easy way to perform recursive submodule fetching with access tokens?
I tried another approach which involved using the private key .pem
file for my github app as an SSH identity. This involved running ssh-agent bash -c 'ssh-add /path/to/private-key.pem; git clone --recurse-submodules git@github.com:owner/repo.git'
, but that ended up with a Permission denied (publickey)
error which makes sense since the .pem
file isn't meant to have access to repositories, just to authenticate the GitHub app.
What is the right way to perform recursive submodule cloning/fetching when writing a GitHub app?
If you think using HTTPS will be easier for submodules, you can add to your configuration:
git -c url."https://x-access-token:<token>@github.com/".insteadOf='git@github.com/' clone ...
For any submodule with a GitHub SSH URL, that would use an HTTPS URL instead (with your access token).