我可以在本地编辑github-actions的main.workflow文件吗?

7
如果我在本地更改main.workflow文件,而不是在master分支中进行更改,然后提交并推送更改,我会从push命令中得到以下错误提示:
> git diff
diff --git a/.github/main.workflow b/.github/main.workflow
index 135d8ea..0a13a28 100644
--- a/.github/main.workflow
+++ b/.github/main.workflow
@@ -6,7 +6,7 @@ workflow "Build and Test in PR" {
   ]
 }

-action ".NET Core CLI" {
+action ".NET Core CLI"  {
   uses = "./.github/net-core/"
   args = "test"
 }

> git push
! [remote rejected] my-branch -> my-branch (refusing to allow an integration to create or update .github/main.workflow)
error: failed to push some refs to 'https://github.com/my-user-name/my-repo.git'

抱歉,无法复制那个。您有可能在使用GitHub桌面版进行推送吗?目前它无法处理main.workflow文件。 - maxheld
@maxheld 问题可能出在Github的存储库设置上。 - baruchiro
2个回答

7

即使使用了 .yml 工作流文件,我仍然遇到了这个问题。原来问题出在我使用的是 HTTPS 远程而不是 SSH。

为了解决 Github API 中的这个问题,我只需使用 SSH 远程而不是 HTTPS。

你可以通过以下方式查看你是否正在使用 HTTPS 或 SSH:

$ git remote -v
> origin  https://github.com/USERNAME/REPOSITORY.git (fetch)
> origin  https://github.com/USERNAME/REPOSITORY.git (push)

如果出现https://而不是git (SSH),请注意。

然后执行:

git remote set-url origin git@github.com:USERNAME/REPOSITORY.git

然后验证更改。
$ git remote -v
# Verify new remote URL
> origin  git@github.com:USERNAME/REPOSITORY.git (fetch)
> origin  git@github.com:USERNAME/REPOSITORY.git (push)

更多阅读:Github文档关于将远程URL从HTTPS切换到SSH


2
如果您正在使用GitHub桌面版,目前存在一个错误,导致在尝试从GitHub Actions推送提交时出现此错误。作为解决方法,您可以在此问题的修复发布之前使用Git API。"最初的回答"

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接