GitHub Actions - 将公共存储库克隆到我的私有存储库?

时间:2020-12-19 16:14:42

标签: git github github-actions

我在 Github 上有一个想要克隆的公共存储库。

我的目标是设置一个 Github 操作,每个月一次,它会克隆此存储库并将任何新更改从公共存储库(托管在 Github 上)上传到我的私人存储库。

这是我目前的 yml 文件:

name: Clone Repo Copy

on:
  schedule:    
      - cron: "0 0 1 * *"
  push:
    branches:
      - main

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          repository: aws/aws-sdk-java-archetype
          token: ${{ secrets.GITHUBPAT }}
      - uses: actions/checkout@v2
      - run: |
          git config user.name github-actions
          git config user.email github-actions@github.com
          git add .
          git commit -m "generated"
          git push

(我的 secrets.GITHUBPAT 是我的 Github 个人访问令牌,它可以出于调试目的访问所有内容)

但是,正如预期的那样,它不起作用,这是我的日志:https://pastebin.com/tHLP0rn5(已编辑以删除用户名和存储库) 如何让 GitHub Actions 克隆公共存储库并将其推送到我的私有存储库?

2 个答案:

答案 0 :(得分:0)

如果您只想将更改推送到镜像存储库,则无需添加和提交任何内容。

在这种情况下,使用 git remote add mirror https://url.to.your.private.repo 然后推送 git push mirror branchname,源分支上不存在的提交将同步到远程。

这假设镜像是一个精确的副本,并且人们也不会将更改推送到该存储库,在这种情况下,过程会有点困难。

答案 1 :(得分:0)

您可以使用 Git Sync Action 之类的操作,它甚至适用于独立/非分叉的存储库。