## 背景
代码托管在 GitLab 上,希望同步一份到 GitHub 做备份和展示。
## 方法一:使用 GitLab CI
创建 `.gitlab-ci.yml`:
```yaml
sync-to-github:
stage: deploy
only: [main]
script:
- git remote add github https://$GITHUB_TOKEN@github.com/username/repo.git
- git push github HEAD:main --force
```
## 方法二:GitLab Push Mirror
Settings → Repository → Mirroring repositories → 填入 GitHub URL。
## 方法三:服务器 cron
```bash
0 3 * * * cd /path/to/repo && git fetch --all && git push github --all
```