Github Actions是Github推出的自动化CI/CD的功能,我们将使用Github Actions让Github仓库同步到Gitee。
1、生成SSH公钥
执行命令:ssh-keygen -t rsa -C "youremail@example.com"
,连续三次回车,id_rsa 为私钥
,id_rsa.pub为公钥
如果提示:already exists(已经存在),则可以到电脑位置:C:\Users\电脑账号名\ .ssh 直接使用
不使用默认SSH参考:生成/添加SSH公钥
2、GitHub项目配置SSH密钥
在Github项目
Settings
->Secrets
->Actions
,名称为:GITEE_RSA_PRIVATE_KEY
,值为:上面生成SSH的私钥
3、GitHub配置SSH公钥
在Github
Settings
->SSH and GPG keys
->New SSH key
,名称为:GITEE_RSA_PUBLIC_KEY
,值为:上面生成SSH的公钥
4、Gitee配置SSH公钥
在Gitee
设置
->安全设置
->SSH公钥
,标题为:GITEE_RSA_PUBLIC_KEY
,值为:上面生成SSH的公钥
5、GitHub创建Github workflow
在Github项目
Actions
创建一个新的workflow
name: Sync To Gitee
on: [ push, delete, create ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Sync to Gitee
uses: wearerequired/git-mirror-action@master
env:
# 注意在 Settings->Secrets 配置 GITEE_RSA_PRIVATE_KEY
SSH_PRIVATE_KEY: ${{ secrets.GITEE_RSA_PRIVATE_KEY }}
with:
# 注意替换为你的 GitHub 源仓库地址
source-repo: git@github.com:github-username/github-repositoryname.git
# 注意替换为你的 Gitee 目标仓库地址
destination-repo: git@gitee.com:gitee-username/gitee-repositoryname.git