GitHub Repository Sync
目录
1 多个Remote
让一个本地 Git Repository 使用多个 Remote, git push
时, 同时推送到多个 Remote, 参考 git remote set-url --add <name> <newurl>
, 运行命令, 比如:
git remote set-url --add origin [email protected]:senzyo_sama/blog.git
使用 git remote -v
查看得到类似信息:
origin [email protected]:senzyo/blog.git (fetch)
origin [email protected]:senzyo/blog.git (push)
origin [email protected]:senzyo_sama/blog.git (push)
这样在 git push
时, 就会同时推送到两个源。
2 从上游同步已经Fork的仓库
- 打开 https://github.com/settings/tokens 生成 Fine-grained personal access tokens。
- Repository access 选择全部仓库或指定仓库。
- Permissions 的 Repository permissions 设置 Contents 为
Read and write
即可。 - 生成 token 并复制。
- 在你专门用于运行 GitHub Actions 来同步的 Repository 中点击 Settings → Secrets and variables → Actions → New repository secrets。
Name
填写PERSONAL_TOKEN
,Secret
粘贴刚才的 token。- 按照你的需要编辑下面的 GitHub Actions 文件。
name: Pull from upstream every 3 days
on:
schedule:
- cron: "0 20 */3 * *" # 4:00 AM UTC+8
workflow_dispatch:
push:
branches:
- master
jobs:
ChatGemini:
name: Sync ChatGemini
runs-on: ubuntu-latest
steps:
- name: Sync ChatGemini
run: |
git clone --branch master https://github.com/bclswl0827/ChatGemini.git
cd ChatGemini
git remote set-url origin https://${{ secrets.PERSONAL_TOKEN }}@github.com/senzyo/ChatGemini.git
git push -uf origin master:master
github-readme-stats:
name: Sync github-readme-stats
runs-on: ubuntu-latest
steps:
- name: Sync github-readme-stats
run: |
git clone --branch master https://github.com/anuraghazra/github-readme-stats.git
cd github-readme-stats
git remote set-url origin https://${{ secrets.PERSONAL_TOKEN }}@github.com/senzyo/github-readme-stats.git
git push -uf origin master:master
3 推送GitHub仓库到GitLab
- 打开 https://gitlab.com/-/user_settings/personal_access_tokens 生成个人访问令牌。
- 注意: 选择范围勾选
api
,read_api
,read_user
,read_repository
,write_repository
。 - 生成 token 并复制。
- 在你专门用于运行 GitHub Actions 来同步的 Repository 中点击 Settings → Secrets and variables → Actions → New repository secrets。
Name
填写GITLAB_PERSONAL_TOKEN
,Secret
粘贴刚才的 token。- 按照你的需要编辑下面的 GitHub Actions 文件。
name: Push to GitLab every 3 days
on:
schedule:
- cron: "0 20 */3 * *" # 4:00 AM UTC+8
workflow_dispatch:
push:
branches:
- master
jobs:
as-gist:
name: Sync as-gist
runs-on: ubuntu-latest
steps:
- name: Sync as-gist
run: |
git clone --branch master https://github.com/senzyo/as-gist.git
cd as-gist
git remote set-url origin https://oauth2:${{ secrets.GITLAB_PERSONAL_TOKEN }}@gitlab.com/senzyo_sama/as-gist.git
git push -uf origin master:master
blog:
name: Sync blog
runs-on: ubuntu-latest
steps:
- name: Sync blog
run: |
git clone --branch master https://github.com/senzyo/blog.git
cd blog
git remote set-url origin https://oauth2:${{ secrets.GITLAB_PERSONAL_TOKEN }}@gitlab.com/senzyo_sama/blog.git
git push -uf origin master:master