Skip to content

Commit 3b9b8c8

Browse files
authored
docs: update README.md (actions#1971)
Add a scenario where it is necessary to push a commit to a pull request.
1 parent 11bd719 commit 3b9b8c8

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

README.md

+26
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ Please refer to the [release page](https://github.com/actions/checkout/releases/
143143
- [Checkout pull request HEAD commit instead of merge commit](#Checkout-pull-request-HEAD-commit-instead-of-merge-commit)
144144
- [Checkout pull request on closed event](#Checkout-pull-request-on-closed-event)
145145
- [Push a commit using the built-in token](#Push-a-commit-using-the-built-in-token)
146+
- [Push a commit to a PR using the built-in token](#Push-a-commit-to-a-PR-using-the-built-in-token)
146147

147148
## Fetch only the root files
148149

@@ -288,6 +289,31 @@ jobs:
288289
```
289290
*NOTE:* The user email is `{user.id}+{user.login}@users.noreply.github.com`. See users API: https://api.github.com/users/github-actions%5Bbot%5D
290291

292+
## Push a commit to a PR using the built-in token
293+
294+
In a pull request trigger, `ref` is required as GitHub Actions checks out in detached HEAD mode, meaning it doesn’t check out your branch by default.
295+
296+
```yaml
297+
on: pull_request
298+
jobs:
299+
build:
300+
runs-on: ubuntu-latest
301+
steps:
302+
- uses: actions/checkout@v4
303+
with:
304+
ref: ${{ github.head_ref }}
305+
- run: |
306+
date > generated.txt
307+
# Note: the following account information will not work on GHES
308+
git config user.name "github-actions[bot]"
309+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
310+
git add .
311+
git commit -m "generated"
312+
git push
313+
```
314+
*NOTE:* The user email is `{user.id}+{user.login}@users.noreply.github.com`. See users API: https://api.github.com/users/github-actions%5Bbot%5D
315+
316+
291317
# License
292318

293319
The scripts and documentation in this project are released under the [MIT License](LICENSE)

0 commit comments

Comments
 (0)