title: How to recursively clone repo for Github App
body: <p>I'm developing a Github app that needs to be able to clone Github repositories whenever a push event occurs.</p>
  <p>I've successfully set everything up including the server and can <a href="https://docs.github.com/en/developers/apps/authenticating-with-github-apps#http-based-git-access-by-an-installation" rel="nofollow noreferrer">clone repositories using using access tokens</a> however I'm having some trouble with repositories that have submodules.</p>
  <p>I find that using <code>git clone --recurse-submodules https://x-access-token:&lt;token&gt;@github.com/owner/repo.git</code> doesn't work if <code>repo.git</code> has submodules configured with SSH. Is there an easy way to perform recursive submodule fetching with access tokens?</p>
  <p>I tried another approach which involved using the pivate key <code>.pem</code> file for my github app as an SSH identity. This involved running <code>ssh-agent bash -c 'ssh-add /path/to/private-key.pem; git clone --recurse-submodules git@github.com:owner/repo.git'</code> but that ended up with a <code>Permission denied (publickey)</code> error which makes sense since the <code>.pem</code> file isn't meant to have access to repositories, just to authenticate the github app.</p>
  <p>What is the right way to perform recursive submodule cloning/fetching when writing a Github app?</p>