Git & GitHub Interview Question #104
What is GITHUB_TOKEN in GitHub Actions?
Advanced GitHub Actions, Repository Internals, Submodules, LFS & Diagnostic Tools Senior Advanced
Quick Interview Answer
GITHUB_TOKEN is an automatically generated token made available to workflow jobs for authenticated operations against the repository and GitHub APIs. Its effective capabilities depend on repository settings and the workflow's permissions configuration.
Detailed Explanation
GITHUB_TOKEN is an automatically generated token made available to workflow jobs for authenticated operations against the repository and GitHub APIs. Its effective capabilities depend on repository settings and the workflow's permissions configuration.
It is preferable to long-lived personal credentials for many repository automation tasks because it is scoped to the workflow context and expires. Workflows should still explicitly minimize its permissions.
Code Example
permissions:
contents: read
issues: write
steps:
- name: Example
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: echo "Use token with required permissions only"