# GitHub Cloning from GFW-Blocked Chinese Servers

When `github.com` is blocked (TLS timeout on port 443), these approaches work in order of reliability:

## 1. GitHub API ZIP Download (MOST RELIABLE)

`api.github.com` often remains accessible even when `github.com` is blocked.
Download the repo as a ZIP archive via the API:

```bash
# Requires a GitHub token (classic or fine-grained with repo read)
TOKEN="ghp_xxx"
OWNER="Keibott"
REPO="icoach"

curl -sL -o repo.zip \
  -H "Authorization: Bearer $TOKEN" \
  "https://api.github.com/repos/$OWNER/$REPO/zipball"

unzip repo.zip -d extract/
subdir=$(ls extract | head -1)
cp -r extract/"$subdir"/* /path/to/dest/
```

**Notes:**
- Works for both public and private repos
- ZIP size is reasonable (no .git history)
- `api.github.com` resolves to a different IP range than `github.com`
- Fine-grained tokens are sufficient (no `admin:public_key` scope needed)

## 2. SSH over Port 443

GitHub's `ssh.github.com:443` bypasses the port 443 HTTP block:

```bash
# First, test connectivity:
ssh -T -o ConnectTimeout=10 -o StrictHostKeyChecking=no git@ssh.github.com

# Clone:
GIT_SSH_COMMAND="ssh -o ConnectTimeout=10" \
  git clone ssh://git@ssh.github.com:443/OWNER/REPO.git
```

**Requires:** SSH key added to GitHub account. If you have a token, add the key via API:
```bash
ssh-keygen -t ed25519 -C "server" -f ~/.ssh/id_ed25519_gh -N ""
# Upload to GitHub (classic token with admin:public_key scope required)
curl -X POST -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d "{\"title\":\"server-key\",\"key\":\"$(cat ~/.ssh/id_ed25519_gh.pub)\"}" \
  "https://api.github.com/user/keys"
```

**Pitfall:** Fine-grained tokens do NOT have access to `/user/keys` endpoint (returns 404).

## 3. Mirror Sites (UNRELIABLE, DON'T WASTE TIME)

| Mirror | Result |
|--------|--------|
| `gitcode.com` | Only mirrors popular repos; private/user repos → 403 |
| `gitclone.com` | 502 errors |
| `kkgithub.com` | Requires login for clone; ZIP downloads → 404 |
| `ghproxy.com` | Connection refused |
| `mirror.ghproxy.com` | Connection refused |
| `hub.fastgit.xyz` | Timeout |

**Don't try mirrors for user repos. Go straight to API approach.**

## When All Else Fails

Have the user:
1. Clone locally and send as ZIP via WeChat/email
2. Or: make the repo public (SSH 443 + public repo = no auth needed)
