Use SSH to clone on Cloudflare Worker instead of HTTPS

Cloudflare workers are unable to clone source code via HTTPS, even permissions are set.

During the migration from GitHub Pages to Cloudflare Pages, I got stuck on the git clone command on Cloudflare’s Worker. After checking the repository permissions, I still could not find the reason for the failure. I considered it might be a Cloudflare issue and began searching for a solution. I found a post on Stack Overflow that suggested using SSH instead of cloning via HTTPS. By following this solution from Stack Overflow, the cloning stage succeeded. Thank you, Cloudflare.

Solution

Your original .gitmodules content:

[submodule "themes/typo"]
	path = themes/
    url = https://github.com/<username>/hexo-theme-typo.git

Run the command in your repo:

git submodule set-url themes/typo git@github.com:<username>/hexo-theme-typo.git

Updated .gitmodules content:

[submodule "themes/typo"]
	path = themes/
    url = git@github.com:<repo_name>/hexo-theme-typo.git

Here’s my orignal error log on Cloudflare Worker:

00:02:24.374	Cloning repository...
00:02:25.196	From https://github.com/<my repo>/<my repo>.github.io
00:02:25.197	 * branch            1fdb7fe31345e99a228ec39199e1471f486e3180 -> FETCH_HEAD
00:02:25.197	
00:02:25.226	HEAD is now at 1fdb7fe update files
00:02:25.227	
00:02:25.649	Submodule 'themes/typo' (https://github.com/<my repo>/hexo-theme-typo.git) registered for path 'themes/typo'
00:02:25.650	Cloning into '/opt/buildhome/clone/themes/typo'...
00:02:25.650	fatal: could not read Username for 'https://github.com': Input/output error
00:02:25.650	fatal: clone of 'https://github.com/<my repo>/hexo-theme-typo.git' into submodule path '/opt/buildhome/clone/themes/typo' failed
00:02:25.651	Failed to clone 'themes/typo'. Retry scheduled
00:02:25.651	Cloning into '/opt/buildhome/clone/themes/typo'...
00:02:25.651	fatal: could not read Username for 'https://github.com': Input/output error
00:02:25.651	fatal: clone of 'https://github.com/<my repo>/hexo-theme-typo.git' into submodule path '/opt/buildhome/clone/themes/typo' failed
00:02:25.651	Failed to clone 'themes/typo' a second time, aborting
00:02:25.651	
00:02:26.477	Failed: error occurred while updating repository submodules
Reference

Deploying repos with submodules using cloudflare pages