Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I push to protected github branches with a deploy key

Tags:

github

We have github enterprise set up at work and I want a travis build to push code back to the repo as part of the master branch build. It basically updates the changelog, commits the file and need to push back to the repo. The problem is that we have protected branches, and trying to push with the deploy key set up with travis yields:

remote: error: Required status check "continuous-integration/travis-ci" is expected.
At least one approved review is required.        
! [remote rejected]   master -> master (protected branch hook declined)

It doesn't help that the protected branch is set up to allow admins to override, becuase the deploy key is not regarded as an admin AFAIU.

like image 993
Nilzor Avatar asked Aug 02 '17 07:08

Nilzor


People also ask

How do I push a protected branch in GitHub?

By default, GitHub blocks force pushes on all protected branches. When you enable force pushes to a protected branch, you can choose one of two groups who can force push: Allow everyone with at least write permissions to the repository to force push to the branch, including those with admin permissions.

How do I use GitHub deploy key?

In the upper-right corner of any GitHub page, click your profile photo, then click Your profile. On your profile page, click Repositories, then click the name of your repository. From your repository, click Settings. In the sidebar, click Deploy Keys, then click Add deploy key.

Can you rebase a protected branch?

Interactive rebase and reword are disabled for pushed commits of protected branches, however, it is possible to do a regular rebase.


1 Answers

Now in 2021 the documentation says that "[d]eploy keys with write access can perform the same actions as an organization member with admin access". If you disable the Include administrators restriction, the deploy key can be used to push to the protected branch.

Include administrators option screenshot

like image 181
piedar Avatar answered Oct 22 '22 15:10

piedar