Interview Prep/Git & GitHub/GitHub, Actions and Pull Request Issues

In CI, `gh pr comment` fails with `HTTP 401: Bad credentials`, or locally `gh` says `You are not logged into any GitHub hosts. To log in, run: gh auth login`.

BeginnerTroubleshootingGitHub, Actions and Pull Request Issues
Answer

Likely causes → gh found no token: in Actions it needs GH_TOKEN (or GITHUB_TOKEN) in the step's environment. A 401 means the token is set but expired, revoked or malformed.

Diagnose →

gh auth status
env | grep -E '^(GH|GITHUB)_TOKEN=' | cut -c1-12

Fix →

- run: gh pr comment "$PR" --body "Deployed to staging"
  env:
    GH_TOKEN: ${{ github.token }}
    PR: ${{ github.event.pull_request.number }}
permissions:
  pull-requests: write

Locally: gh auth login (or gh auth refresh -s repo,workflow to add scopes).

Prevent → Always pass GH_TOKEN explicitly in workflow steps that call gh.

All Git & GitHub questions Roadmap: Git & GitHub

More on GitHub, Actions and Pull Request Issues