github - remote: error: GH006: Protected branch update failed for refsheadsdevelopment - Stack Overflow

I am using GitHub Actions to increment my angular project version as a last step in my workflow.I conf

I am using GitHub Actions to increment my angular project version as a last step in my workflow. I configured the git user and git email before pushing (i.e, before running 'git push').

git config user.name "${{ secrets.GIT_USER }}"
git config user.email "${{ secrets.GIT_EMAIL }}"

I am getting below error

remote: error: GH006: Protected branch update failed for refs/heads/development.  
remote:
remote: - Changes must be made through a pull request.  
To .git
! \[remote rejected\] development -\> development (protected branch hook declined)
error: failed to push some refs to '.git'

I realised am not using any password or Git PAT for pushing so tried setting the git remote url as below

git remote set-url origin https://x-access-token:${{ secrets.GIT_TOKEN }}@github/thermofisher/de-instrument-storage-service.git

Additional context:

  • My repo is a private repo.

  • The branch ('development') I am trying to push has branch protection rule called Require a pull request before merging checked. Which I should not disable. And also the git user and email that I'm using have admin permission for the repository. So not sure why I am unable to push!

Is there any way, to be able to push changes via GitHub Actions to a protected branch as an admin?

I am using GitHub Actions to increment my angular project version as a last step in my workflow. I configured the git user and git email before pushing (i.e, before running 'git push').

git config user.name "${{ secrets.GIT_USER }}"
git config user.email "${{ secrets.GIT_EMAIL }}"

I am getting below error

remote: error: GH006: Protected branch update failed for refs/heads/development.  
remote:
remote: - Changes must be made through a pull request.  
To https://github/my-repo-name.git
! \[remote rejected\] development -\> development (protected branch hook declined)
error: failed to push some refs to 'https://github/my-repo-name.git'

I realised am not using any password or Git PAT for pushing so tried setting the git remote url as below

git remote set-url origin https://x-access-token:${{ secrets.GIT_TOKEN }}@github/thermofisher/de-instrument-storage-service.git

Additional context:

  • My repo is a private repo.

  • The branch ('development') I am trying to push has branch protection rule called Require a pull request before merging checked. Which I should not disable. And also the git user and email that I'm using have admin permission for the repository. So not sure why I am unable to push!

Is there any way, to be able to push changes via GitHub Actions to a protected branch as an admin?

Share Improve this question asked Nov 19, 2024 at 11:33 GhrVinayGhrVinay 113 bronze badges 7
  • try --force-with-lease – jessehouwing Commented Nov 19, 2024 at 12:04
  • @jessehouwing, Tried git push --force-with-lease, didn't work getting the same error! – GhrVinay Commented Nov 19, 2024 at 17:52
  • I think you need to bypass the user without having to meet pull request required protection rule --> you can refer this doc for more details -> github.blog/changelog/… – Dayananda D R Commented Nov 19, 2024 at 17:52
  • In that case the branch protection rule probably also prevents force pushes. – jessehouwing Commented Nov 19, 2024 at 18:09
  • @DayanandaDR I tried bypass as well, thats when i realised if the git user is already an admin to the repo then no need to explicitly allow that user to bypass. – GhrVinay Commented Nov 21, 2024 at 10:04
 |  Show 2 more comments

1 Answer 1

Reset to default 0

I had to pass the GIT Personal Access Token while cloning the repo..

- name: Checkout
        uses: actions/checkout@v4
        with:
          token: ${{ secrets.GIT_TOKEN }}

From then on I am able to commit/push with the git user which has admin access to the repo and effectively able to bypass the "Require a pull request before merging" check.

I referred to the following: https://www.paulmowat.co.uk/blog/resolve-github-action-gh006-protected-branch-update-failed

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745564501a4633310.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信