githubgithub-actions

remote: error: GH006: Protected branch update failed for refs/heads/development


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.com/my-repo-name.git
! \[remote rejected\] development -\> development (protected branch hook declined)
error: failed to push some refs to 'https://github.com/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.com/thermofisher/de-instrument-storage-service.git

Additional context:

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


Solution

  • 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