Permission Denied to github-actions[bot] (403): Fix
Last updated
Permission to <owner>/<repo>.git denied to github-actions[bot] means a workflow tried to push (a commit, a tag or a branch) and the GITHUB_TOKEN it used only has read access. The fix is one line in the workflow, and in some organisations one setting. This page also covers the other reasons a push by the bot fails.
The exact message
remote: Permission to my-org/my-repo.git denied to github-actions[bot].
fatal: unable to access 'https://github.com/my-org/my-repo/': The requested URL returned error: 403
Fix 1: give the job contents: write
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add CHANGELOG.md
git commit -m "Update changelog" || echo "nothing to commit"
git push
actions/checkout stores the workflow's token for later git commands by default, so a plain git push uses it. Put permissions on the job that pushes, not on the whole workflow, so other jobs stay read-only.
Fix 2: check the organisation and repository default
Under Settings, Actions, General, "Workflow permissions" can be "Read repository contents and packages permissions" (read-only). An organisation owner can force that for every repository. A permissions: block in the workflow can raise it unless the organisation setting prevents it. If the block does nothing, ask an owner.
Fix 3: the push is blocked by a branch rule
A protected branch that requires pull requests, reviews or status checks rejects a direct push from the bot too, with a different message such as GH006: Protected branch update failed. The bot cannot bypass the rule by default. Options are to push to a new branch and open a pull request, or to add the app or the bot to the ruleset's bypass list if your plan supports that.
- uses: peter-evans/create-pull-request@v7
with:
branch: auto/changelog
title: Update changelog
That action needs contents: write and pull-requests: write, and the repository setting "Allow GitHub Actions to create and approve pull requests" turned on.
Fix 4: forks cannot push
For workflows triggered from a pull request opened in a fork, the token is read-only and no permission setting changes that. The workflow cannot push to the fork's branch. Do the write step from a separate workflow triggered by workflow_run, or ask contributors to run the formatter locally.
Fix 5: the workflow wants to push and trigger more workflows
A push made with the GITHUB_TOKEN does not start other workflow runs, which GitHub does to avoid loops. If a pushed commit or tag must trigger a workflow, push with a GitHub App token or a personal access token instead.
Fix 6: pushing a tag or editing workflow files
Pushing a tag needs contents: write as well. Changing a file under .github/workflows is not possible with the GITHUB_TOKEN at all, see refusing to allow a GitHub App to update workflow.
How to prevent it
- Keep default permissions read-only and add
contents: writeonly to the one job that pushes. - Plan for branch rules: push to a branch and open a pull request instead of pushing to
main. - Use a GitHub App token where a push must trigger a follow-up workflow.
- Test the workflow on a branch before relying on it for releases.
FAQ
Why can the bot read but not write?
Newer repositories and organisations default the GITHUB_TOKEN to read-only for safety. You opt in to writes per job.
Is this the same as "Resource not accessible by integration"?
It is the same cause (a missing token permission) seen through git instead of the API. See Resource not accessible by integration.
Does persist-credentials: false break this?
Yes. With it, the token is not kept for later git commands, so git push has nothing to authenticate with. Leave it at the default for jobs that push, or pass the token explicitly.
Can I push from a scheduled workflow?
Yes, with contents: write. Scheduled workflows run on the default branch, so protected-branch rules still apply.
Related
- Permission Denied (publickey) in GitHub Actions: FixFix "git@github.com: Permission denied (publickey)" in GitHub Actions: add an SSH key or deploy key, or switch to an HTTPS token for private repos.
- Refusing to Allow a GitHub App to Update Workflow: FixFix "refusing to allow a GitHub App to create or update workflow without workflows permission": use a PAT or App token with workflow write access.
- Cache Service Responded With 429: FixFix "Failed to restore: Cache service responded with 429" in GitHub Actions: too many cache requests. Upgrade actions/cache, restore once, save once.
- fatal: could not read Username for github.com: FixFix "fatal: could not read Username for 'https://github.com'" in GitHub Actions: private repos, submodules and git dependencies need a token.