Push to restricted master branch #26460
-
Hi all I’m trying to set up a release pipeline in GitHub Actions. As part of this, the release number in the Maven pom.xml is set and pushed back to the master branch. This worked fine when testing in a simple (private) repository. But in the actual repository, we have branch restrictions set on master:
The push to master by GitHub Actions fails with
How can I explicitly allow GitHub Actions to push directly to restricted branches? Found similar discussions (i.e. here), but the proposed solution of adding github-actions[bot] doesn’t work. Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
Hi @pgruetter , Organization administrators, repository administrators, and users with the Maintain role can always push to a protected branch. If you are repository administrators , you could use your personal access token to push changes. You could store it in secrets. Please remember adding persist-credentials: false to checkout@v2. There is my workflow yml example for push with PAT:
|
Beta Was this translation helpful? Give feedback.
-
Thanks a lot for the precise description and mentioning persist-credentials. It worked! |
Beta Was this translation helpful? Give feedback.
-
@pgruetterI’m an Actions newbie and I’m wanting to do what you did but am not finding the right way. In my case, I simply want to push to the same repo, same branch, but a specific directory. I see the answer which mentioned this action, however is this the right thing in my case? Since my workflows are triggered on commit to master, it shouldn’t produce a commit but simply a silent “upload” to that directory and overwrite all contents. Can you maybe give me a little advice? |
Beta Was this translation helpful? Give feedback.
-
Hi @chipzoller |
Beta Was this translation helpful? Give feedback.
-
Thanks for your confirmation. I’ll need to look for another way to go about my workflow. |
Beta Was this translation helpful? Give feedback.
Hi @pgruetter ,
Organization administrators, repository administrators, and users with the Maintain role can always push to a protected branch.
If you are repository administrators , you could use your personal access token to push changes. You could store it in secrets. Please remember adding persist-credentials: false to checkout@v2.
There is my workflow yml example for push with PAT: