代码之家  ›  专栏  ›  技术社区  ›  Cyril N.

推送到另一个分支的Github操作?

  •  0
  • Cyril N.  · 技术社区  · 1 年前

    我已经创建了一个Github操作,当我将代码推送到“暂存”分支时会触发该操作。该操作运行测试,当成功时,我希望它将代码从暂存推送到“prod”分支。

    我做不到。我做错了什么?

    以下是我的Github操作:

    name: Test and Deploy
    on:
      push:
        branches:
          - staging
    jobs:
      test:
        runs-on: ubuntu-latest
        steps:
          - name: Checkout code
            uses: actions/checkout@v3
    
          - name: Set up Python
            uses: actions/setup-python@v4
            with:
              python-version: '3.10'
              cache: 'pip' # caching pip dependencies
    
          - name: Start Redis
            uses: supercharge/redis-github-action@1.5.0
    
          - name: Update pip
            run: pip install --upgrade pip
    
          - name: Install requirements.txt
            run: pip install -r requirements.txt
    
          - name: Install test requirements
            run: pip install pytest pytest-cov sanic-testing==22.12.0 aiosqlite==0.18.0
    
          - name: Test with pytest
            run: pytest tests
    
      deploy:
        needs: test
        runs-on: ubuntu-latest
        steps:
          - name: Checkout code
            uses: actions/checkout@v3
    
          - name: Deploy to prod
            run: |
              git push -u origin prod
    

    上述命令会产生以下错误:

    错误:src refspec prod与任何 错误:无法将某些引用推送到'https://github.com/myproject/repo'

    如果我这样做 git checkout -b prod 首先,我得到以下错误:

    切换到新的分支“prod” 从…起 https://github.com/myproject/repo

    • 分支产品->获取标头
    • [新分支机构]产品->原产地/产品 致命:拒绝合并不相关的历史记录

    我还尝试过:

    运行git checkout-b prod git checkout-b prod git pull origin prod git-push-u原点prod-shell:/usr/bin/bash-e{0}切换到 新分支“prod”来自 https://github.com/myproject/repo *分支
    产品->FETCH_ HEAD*[新分支]产品-> origin/prod提示:您有不同的分支,需要指定如何 以调和它们。提示:您可以运行以下操作之一 在提示之前的某个时间发出的命令:您的下一个pull:hint:hint:git config-pull.rebase false#合并提示:git-config-pull.rebasetrue

    rebase提示:git-config-pull.ff only#仅快进提示:提示:您可以将“git-config”替换为“git-connfig--global”

    设置一个默认提示:所有存储库的首选项。你也可以 仅在命令行上将--rebase、--no rebase、hint:或--ff传递给 重写已配置的默认值per hint:invocation。致命:需要 指定如何协调不同的分支。错误:进程已完成 退出代码为128。

    git checkout-b产品git push-u原始产品外壳: /usr/bin/bash-e{0}已切换到新的分支“prod”to https://github.com/myproject/repo ![拒绝]产品->戳 (先获取)错误:无法将某些引用推送到 'https://github.com/myproject/repo'提示:更新被拒绝 因为远程包含您所提示的工作:本地没有。 这通常是由另一个存储库推送提示引起的: 参考。您可能希望首先集成远程更改提示:(例如。, 'git pull…')然后再推。提示:请参阅“关于 有关详细信息,请参阅“gitpush--help”中的“快进”。

    0 回复  |  直到 1 年前