繁体   English   中英

Github 操作 - 远程 git 推送不起作用

[英]Github actions - remote git push not working

我正在使用github actions在我的其他 git 存储库中推送一些代码。

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
      - name: Push remote
        run: |
          git config user.name "myusername"
          git config user.email "myusername@gmail.com"
          git remote set-url origin "https://myusername:$GIT_TOKEN@github.com/myusername/AnotherRepo"
          git add mytext.txt
          git commit -m "Pushing mytext with remote push"
          git push

GIT_TOKEN设置为当前 git 存储库的存储库机密。 在这个令牌中,我提供了所有权限。

然而我得到了错误:

fatal: repository 'https://github.com/myusername/AnotherRepo.git/' not found.

这里的答案看来,这是一个权限问题。

但是这两个回购都属于我,所以为什么我会收到这个错误。

如果我尝试将文件推送到同一个源存储库中(git 操作正在运行),那么就没有问题。

所以 yaml 动作没有问题。

我错过了什么?

PS。 我也试过${{ secrets.GIT_TOKEN }}

如果您想在当前存储库的 GHA 内的另一个存储库中推送代码,您应在另一个文件夹中检出您的代码(使用path来实现此目的)并使用此文件夹来推送您的代码(使用working-directory来实现此目的)。 例如:

- name: Checkout repository B
  uses: actions/checkout@v2
  with:
      path: './folder-B'
      token: ${{secrets.GITHUB_TOKEN}}
- name: Push remote
  working-directory: './folder-B'
  run: |
      git config user.name "myusername"
      git config user.email "myusername@gmail.com"
      git remote set-url origin "https://myusername:$GIT_TOKEN@github.com/myusername/AnotherRepo"
      git add mytext.txt
      git commit -m "Pushing mytext with remote push"
      git push

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM