33

Well, it is very weird. I'm using Github protection rules to enforce to make pull requests and to trigger TravisCI for every push. However, because of continuous translation, I need a user who should be able to push without making a pull request and avoiding TravisCI status check (for that I use [ci skip]). This user is included in the white list that Github provides in branch protection rules. It worked perfect since last week, suddenly when I try to push with this user I receive this:

remote: Resolving deltas: 100% (5/5), completed with 5 local objects.
remote: error: GH006: Protected branch update failed for refs/heads/master.
remote: error: Required status check "Travis CI - Pull Request" is expected. At least 1 approving review is required by reviewers with write access.
To https://github.com/*****
 ! [remote rejected] master -> master (protected branch hook declined)
error: failed to push some refs to 'https://*****'

It is very weird since it always worked till now. And, the user has permissions to push without making a pull request and it is skipping Travis with through the commit message so I do not understand why Github is asking me about status check and approvals.

7_R3X
  • 3,904
  • 4
  • 25
  • 43
David Escalera
  • 475
  • 1
  • 4
  • 8
  • 3
    You need to create a pull request and have it approved by someone other than you. Pushing directly into the master branch has been disabled – sechanakira Oct 01 '18 at 10:40
  • 2
    @sechanakira So you mean that recently they disabled the possibility of pushing directly on master branch? But with my user which is the owner of the repo I can push there directly... Also if they did that it is going to deny a lot of automated processes :S – David Escalera Oct 01 '18 at 10:43

8 Answers8

26

The latest issue I had :

remote: error: GH006: Protected branch update failed for refs/heads/master.
remote: error: Cannot force-push to this protected branch
To https://github.com/org/project.git
 ! [remote rejected]     master -> master (protected branch hook declined)
error: failed to push some refs to 'https://github.com/org/project.git 

Because I'm admin/owner I was able to go and do the following and that helped me to resolve the push problem. Steps : --> Settings -->Branches --> Tick Allow force pushes Permit force pushes for all users with push access. That will do the work.

JohnBegood
  • 652
  • 1
  • 7
  • 8
12

I solved it finally giving admin access to the user instead of just write access. Now it is able to push avoiding approvals and status check. But I don't understand why does not work just being in the white list of protection branch rules... It worked before, looks like GitHub made some changes...

David Escalera
  • 475
  • 1
  • 4
  • 8
10

Master [now Main] is a protected branch. You need to make a new branch and push that instead.

Seen in branch protection rules: enter image description here

Kermit
  • 4,922
  • 4
  • 42
  • 74
4

In my case a security rule was somehow created for the repo. This rule allowed only admins to push. I deleted that rule and things started working as expected.

Repo > Settings > Branches > Branch protection rules [Delete]

singh2005
  • 1,251
  • 12
  • 19
3

In my case a Branch Protection Rule was misfiring. Deleting the rule, then recreating it in GitHub fixed the issue.

O Wigley
  • 157
  • 1
  • 4
2

In my case, I made a Pull (Rebase) first, and then I made Push

JotaPardo
  • 817
  • 9
  • 27
1

In my case git push origin HEAD fixed the problem.

Theodory
  • 301
  • 1
  • 3
  • 12
-1

In this situation granting admin access is not solution and even not recommended. Do not try to merge code from one-branch(feature) to another(feature) branch. Follow below steps in high level overview-

  1. Push your local feature branch changes to remote feature branch.
  2. Go to UI and Create Pull Request by comparing all the "Files changed" review.
  3. Add reviewers to review and approve these changes.
  4. Reviewer will review changes and submit review comment.
  5. Approve changes so that those are ready for merge.
  6. Click on "Merge" button to merge your changes from one branch to another(Merge protected) branch. That's it.