gitmacosgithub

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


I am stuck to Github issue which seems weired to me.

I have been using Github from past 2 years. Recently I occured one issue which is given below:

remote: Resolving deltas: 100% (12/12), completed with 12 local objects.
remote: error: GH006: Protected branch update failed for refs/heads/preprod.
remote: error: Changes must be made through a pull request.

I am working in organization where we have kept our repo as Private Repo.

We have different environment repo such as (staging, preprod, prod / master)

We have 2 Authentication Rules.

  1. Must be approved by one of the person
  2. It has some protected branches like staging,preprod, prod/master.

I am unable to push to protected branch from few days. I am also part of the team to push the code in protected branch.

I am using MAC. I know this there are many solutions but it doesnt work for me.

Update (28 November 2023): Forget to update here the best around way to resolve the issue.

  • If you are not able to resolve the issue then quick fix will be to create a new branch from the branch you were not allowed to push the changes and merge the current branch in newly created branch. (Eg. A is preprod branch and B is your feature/123 branch then create new branch from preprod branch named as feature/123-preprod. Now merge your changes of feature/123 branch in feature/123-preprod branch and push the changes to remote. After this create PR against preprod with newly branch feature/123-preprod.)
  • In this particular scenario there will be no RMC and you can easily merge the changes in preprod.
  • Also dont forget to delete the feature/123-preprod branch after your deployment to avoid confusion.
  • This is will only work if you have selected only few selected branches under protected branch.

Solution

  • That means the rules (in beta in April 2023) are now in effect for all repositories.

    Make sure to follow "Enhancements for admins bypassing branch protections on github.com"

    Or, as shown in this discussion yesterday (June 23, 2023), you would need to remove the rule:

    https://user-images.githubusercontent.com/5814919/248411819-7859c48b-3f2e-4ba6-b072-c6f0ec9c3027.png


    The OP 000723-weict suggests a workaround using branching and pull requests, which is different from my approach focused on understanding and potentially adjusting repository rules and branch protections.

    The OP suggests creating a new branch (e.g., feature/123-preprod) from the protected branch (preprod), then merging the changes from the original feature branch (feature/123) into this new branch. That method bypasses the direct push restrictions on the protected branch by using an intermediary branch for merging changes.
    A pull request is then created to merge the intermediary branch into the protected branch. The intermediary branch is deleted after successful deployment to maintain clarity in the repository.

    My approach involves understanding and utilizing the new GitHub rules and enhancements for admins bypassing branch protections. But it might require administrative access or changes to the repository rules, which might not always be feasible.