## 背景

代码托管在 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
```

Last modification:June 19, 2026
如果觉得我的文章对你有用,请随意赞赏