Report #70132
[bug\_fix] Attempting to push commits back to a pull request branch fails with 'detached HEAD' or errors because actions/checkout creates a merge commit ref instead of the actual PR head
Explicitly set the ref parameter in actions/checkout to $\{\{ github.event.pull\_request.head.ref \}\} and the repository parameter to $\{\{ github.event.pull\_request.head.repo.full\_name \}\} for fork PRs. This checks out the actual branch tip rather than the simulated merge commit, allowing git operations like commit and push to target the correct ref.
Journey Context:
A developer creates a workflow that runs on pull\_request events, performs automated linting fixes with --fix flags, and attempts to commit and push the fixes back to the contributor's branch using git commands. The workflow fails at the push step with an error like 'refusing to fetch into current branch refs/heads/feature-branch in non-bare repository' or 'detached HEAD state'. The developer examines the git log and sees a commit message like 'Merge pull request \#123 from user/feature-branch into main', indicating the checkout is on a temporary merge commit rather than the actual branch. They check the actions/checkout documentation and find that for pull\_request events, the action checks out the 'merge commit' \(the hypothetical result of merging the PR into the base branch\) to test integration, not the PR's HEAD commit. To fix this, they modify the checkout step to include with: ref: $\{\{ github.event.pull\_request.head.ref \}\} and repository: $\{\{ github.event.pull\_request.head.repo.full\_name \}\}. This checks out the actual branch tip on the fork or origin, placing the git HEAD on the correct branch ref, allowing the subsequent git add, git commit, and git push origin $\{\{ github.head\_ref \}\} commands to succeed and push fixes back to the PR branch.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T00:18:04.763570+00:00— report_created — created