Post

Automating GitHub Tasks with the GitHub CLI

This guide shows you how to drive common GitHub tasks from the terminal with the gh CLI: opening and reviewing PRs, managing issues, configuring autolinks, and cutting releases. Each section is a self-contained recipe — jump to the one you need.

Prerequisites

  • GitHub CLI installed and authenticated (steps below)
  • A GitHub account with access to the repos you’re targeting

Problem

You need to automate repetitive GitHub tasks — creating PRs, managing issues, setting up repository automation — without leaving the terminal.

Install and authenticate

If you haven’t already done this (it’s covered in Getting Started: Windows DevOps):

1
2
winget install github.cli
gh auth login

Follow the prompts:

  1. Choose GitHub.com
  2. Select HTTPS
  3. Type Y to authenticate with browser
  4. Enter the one-time code shown in the terminal

Verify:

1
gh auth status

The browser flow defaults the credential to HTTPS. If you cloned a repo over SSH, run gh auth login again and pick SSH, or gh and git will end up authenticating as different identities on the same repo.

Create a pull request

1
2
3
4
5
6
7
8
# Create PR from current branch
gh pr create --title "feat: add feature" --body "Description of changes"

# Create PR with specific base branch
gh pr create --base main --title "fix: bug fix"

# Create draft PR
gh pr create --draft --title "WIP: feature in progress"

Review pull requests

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# List open PRs
gh pr list

# View a PR
gh pr view 42

# Check out a PR locally
gh pr checkout 42

# Approve a PR
gh pr review 42 --approve

# Merge a PR
gh pr merge 42 --squash

Manage issues

1
2
3
4
5
6
7
8
# Create an issue
gh issue create --title "Bug: login fails" --body "Steps to reproduce..."

# List open issues
gh issue list

# Close an issue
gh issue close 15 --reason "completed"

Autolinks connect GitHub issue references to external systems (Jira, Linear). The two scripts below live in this repo’s Powershell/ folder, so run them from the repo root — relative paths won’t resolve from elsewhere.

1
2
3
4
5
# Audit existing autolinks for all repos in an organization
./Powershell/GitHub-cli-Audit-Autolinks.ps1

# Create autolinks for a repo (maps PROJ-123 → Jira)
./Powershell/GitHub-cli-Create-Autolinks.ps1

Available scripts:

Work with releases

1
2
3
4
5
6
7
8
# Create a release
gh release create v1.0.0 --title "v1.0.0" --notes "First stable release"

# List releases
gh release list

# Download release assets
gh release download v1.0.0

Verify It Worked

1
2
3
4
5
# Confirm authentication
gh auth status

# Test API access
gh api user --jq '.login'

Troubleshooting

“gh: command not found”

GitHub CLI is not installed or not on PATH.

1
2
winget install github.cli
# Then restart PowerShell

“gh auth status” shows “You are not logged in”

1
2
gh auth logout
gh auth login

See Also

This post is licensed under CC BY 4.0 by the author.