fork之后,你自己的GitHub仓库更新

相信吾爱很多小伙伴用过BILIBILI-HELPER,
有没有用了几天后,项目连续报错?
原因: 项目代码旧了,需要更新
更新方法:
1.fork仓库后,将你的仓库拉到本地,如果没有源头仓库,则添加源头仓库
    git remote add upstream https://github.com/JunzhouLiu/BILIBILI-HELPER.git
2.更新上游仓库main分支的代码(pull操作实际上是 fetch+merge)
     git pull upstream main
3. 将从源头仓库更新后的代码推送到你自己的github仓库
     git push origin main
这样你就能快速的从我的仓库拉取最新的代码,并更新到你自己的仓库里了。自定义配置的同学,要注意config.json 不要被我的文件覆盖了。
如果你提交代码太慢,可以考虑git挂代{过}{滤}理,git 加代{过}{滤}理的方法是
git config --global https.proxy https://代{过}{滤}理服务IP:端口

取消,则是

git config --global --unset https.proxy




以上介绍的是手动方式,当然会有自动方式(两种):

更新和帮助

1.使用 Github Actions 自动同步源仓库代码

参阅Issue8 使用GitHub Actions任务自动同步源仓库代码

该方案来自 @happy888888 #6 ,由于本操作会覆盖用户自己的config.json配置文件,所以暂时没有合并到main分支,所以请使用自定义功能的朋友请慎用。

在./github/workflows目录下创建auto_merge.yml文件,内容如下

name: auto_merge

on:
  workflow_dispatch:
  schedule:
    - cron: 0 8 * * fri
    # cron表达式,每周五16点执行一次,actions任务时区为UTC时区。 


jobs:
  merge:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout
      uses: actions/checkout@v2
      with:
        ref: main
        fetch-depth: 0
        lfs: true

    - name: Set git identity
      run : |
        git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
        git config --global user.name "github-actions[bot]"
    - name: Load upstream commits
      run: |
        git update-index --assume-unchanged ./src/main/resources/config.json
        git pull https://github.com/JunzhouLiu/BILIBILI-HELPER.git --log --no-commit
    - name: Apply commit changes
      run: |

        if [ -f ./.git/MERGE_MSG ]; then
        mkdir ./tmp && cp ./.git/MERGE_MSG ./tmp/message
        sed -i "1c [bot] AutoMerging: merge all upstream's changes:" ./tmp/message
        sed -i '/^\#.*/d' ./tmp/message
        git commit --file="./tmp/message"
        else
        echo "There is no merge commits."
        fi
    - name: Push Commits
      env:
        DOWNSTREAM_BRANCH: main
        TZ: Asia/Shanghai
      run: git push origin $DOWNSTREAM_BRANCH

2. 使用Pull APP[推荐]

参阅 Pull APP 

a GitHub App that keeps your forks up-to-date with upstream via automated pull requests.

posted @ 2020-12-30 00:59  刘江龙  阅读(1217)  评论(0编辑  收藏  举报