GitHub CLI Mastery: 20 Commands Every Developer Should Know

Published: April 3, 2026 | Updated: April 2026

The GitHub CLI (`gh`) has transformed how developers interact with GitHub. Instead of switching between terminal and browser, you can manage repos, issues, pull requests, releases, and moreβ€”all from the command line. This comprehensive guide covers the 20 commands that will supercharge your GitHub workflow in 2026.

Getting Started

Installation

# macOS
brew install gh

# Linux (Ubuntu/Debian)
sudo apt install gh

# Windows
winget install GitHub.cli

# Or download from: https://cli.github.com/

Authentication

# Authenticate with GitHub
gh auth login

# Check authentication status
gh auth status

# Log out
gh auth logout
Pro tip: Use `gh auth refresh` to refresh your authentication token if you encounter permission errors.

The 20 Essential Commands

Repository Commands (5 Commands)

1. Clone a Repository

# Basic clone
gh repo clone owner/repo

# Clone with custom directory name
gh repo clone owner/repo -- --dirname my-project

# Clone with all branches
git clone --mirror https://github.com/owner/repo

2. Create a Repository

# Create repository in current directory
gh repo create my-project --source=. --private

# Create standalone repository
gh repo create my-org/my-project --public

# Create from template
gh repo create my-project --template owner/template-repo

Flags:

  • `--private`, `--public`, `--internal` β€” visibility
  • `--source=.` β€” use current directory
  • `--push` β€” push after creation
  • `--team` β€” add to organization team

3. Fork a Repository

# Fork current repo
gh repo fork

# Fork specific repo
gh repo fork owner/repo --clone=true

# Fork with specific organization
gh repo fork owner/repo --org my-org

4. View Repository Info

# View repo details
gh repo view

# View specific repo
gh repo view owner/repo

# View with readme content
gh repo view owner/repo --web

# View repo and show clone URL
gh repo view owner/repo --json name,url,description

5. Sync Repository

# Sync fork with upstream
gh repo sync owner/repo --source upstream

# Sync with specific branch
gh repo sync owner/repo --branch main

Issue Commands (5 Commands)

6. Create an Issue

# Create issue interactively
gh issue create

# Create with flags
gh issue create --title "Bug in login" --body "Steps to reproduce..." --label bug

# Create from file
gh issue create --title "Feature request" --body-file feature.md

# Assign to milestone
gh issue create --title "Task" --milestone "v2.0"

Useful Flags:

  • `--title` β€” issue title
  • `--body` or `--body-file` β€” issue description
  • `--label` or `--assignee` β€” add labels/assignees
  • `--milestone` β€” add to milestone
  • `--project` β€” add to project board
  • `--web` β€” open in browser instead

7. List Issues

# List open issues in current repo
gh issue list

# List with specific state
gh issue list --state all
gh issue list --state closed

# Filter by label
gh issue list --label bug,urgent

# Filter by assignee
gh issue list --assignee @me

# Search issues
gh issue list --search "error in:title is:open"

8. View and Edit Issues

# View issue in terminal
gh issue view 123

# View in browser
gh issue view 123 --web

# Edit issue
gh issue edit 123 --title "New title" --add-label "enhancement"

# Close issue
gh issue close 123 --comment "Fixed in PR #456"

9. Manage Issue Labels

# List available labels
gh label list

# Create label
gh label create "needs-review" --description "Awaiting code review"

# Edit label
gh label edit "needs-review" --name "awaiting-review" --color "ff0000"

10. Transfer Issue

# Transfer issue to another repo
gh issue transfer 123 owner/other-repo

Pull Request Commands (5 Commands)

11. Create a Pull Request

# Create PR interactively
gh pr create

# Create with flags
gh pr create --title "Add new feature" --body "Description..." --label enhancement

# Create from branch
gh pr create --head my-feature-branch --base main

# Draft PR
gh pr create --draft --title "WIP: New feature"

# Auto-assign reviewers
gh pr create --reviewer alice,bob --title "Feature" --body "Details"

Useful Flags:

  • `--title`, `--body` β€” PR title and description
  • `--base` β€” target branch (default: main)
  • `--head` β€” source branch
  • `--draft` β€” draft PR
  • `--reviewer` β€” request reviews
  • `--assignee` β€” assign PR
  • `--label` or `--project` β€” add labels or project
  • `--milestone` β€” add to milestone
  • `--web` β€” open in browser

12. List Pull Requests

# List open PRs
gh pr list

# List by state
gh pr list --state closed
gh pr list --state merged

# Filter by author
gh pr list --author @me

# Filter by label
gh pr list --label "needs-review"

# Filter by branch
gh pr list --head my-feature

13. View Pull Request

# View PR in terminal
gh pr view 123

# View specific PR
gh pr view owner/repo#123

# View PR diff
gh pr diff 123

# View PR status checks
gh pr checks 123

# View in browser
gh pr view 123 --web

14. Review Pull Requests

# Check out PR locally
gh pr checkout 123

# Approve PR
gh pr review 123 --approve

# Request changes
gh pr review 123 --request-changes --body "Needs improvement on..."

# Comment PR
gh pr review 123 --comment --body "Looks good!"

# Submit review
gh pr review 123 --approve --submit

15. Merge and Manage PRs

# Merge PR
gh pr merge 123 --squash --delete-branch

# Merge with merge commit
gh pr merge 123 --merge --delete-branch

# Rebase and merge
gh pr merge 123 --rebase --delete-branch

# Close PR
gh pr close 123 --comment "Closing in favor of #456"

# Check merge status
gh pr view 123 --json mergeable,state

Workflow and Action Commands (3 Commands)

16. Run GitHub Actions

# List workflow runs
gh run list

# View run details
gh run view 12345

# Watch run progress
gh run watch 12345

# Rerun failed job
gh run rerun 12345

# Download run artifacts
gh run download 12345 --name "build-output"

# Trigger workflow
gh workflow run build.yml --ref my-branch

17. Manage Workflows

# List all workflows
gh workflow list

# View workflow
gh workflow view build.yml

# Enable/disable workflow
gh workflow disable build.yml
gh workflow enable build.yml

# Run workflow
gh workflow run build.yml --env "ENV=prod"

18. Manage GitHub Actions Secrets

# List repo secrets
gh secret list

# Set secret
gh secret set API_KEY --body "your-secret-value"

# Set from env variable
gh secret set API_KEY --body "$API_KEY"

# Delete secret
gh secret delete API_KEY

# List org secrets
gh secret list --org my-org

# Set org secret
gh secret set API_KEY --org my-org --visibility all

Release and Package Commands (2 Commands)

19. Manage Releases

# List releases
gh release list

# View release
gh release view v1.2.3

# Create release
gh release create v1.2.3 --title "Version 1.2.3" --notes "Bug fixes and improvements"

# Create from tag
gh release create --generate-notes

# Upload assets
gh release upload v1.2.3 ./build/myapp --clobber

# Delete release
gh release delete v1.2.3

20. Manage Gist

# Create gist
echo "Hello" | gh gist create

# Create gist from file
gh gist create myfile.js --public

# Create gist with description
gh gist create script.sh --desc "My deployment script"

# List your gists
gh gist list

# View gist
gh gist view abc123

# Edit gist
gh gist edit abc123 --add "new content"

Bonus: GitHub CLI Tips and Tricks

Interactive Mode

# Use interactive selection for many commands
gh issue create  # interactive prompts
gh pr create     # interactive prompts
gh repo clone    # interactive selection

JSON Output for Scripting

# Get JSON output
gh issue list --json number,title,state,labels

# Query specific fields
gh repo view --json name,description,url

# Use in scripts
ISSUES=$(gh issue list --json number --jq '.[].number')
for issue in $ISSUES; do
    gh issue comment $issue --body "Bump!"
done

Alias Commands

# Create aliases in gh config
gh alias set co "pr checkout"
gh alias set i "issue"
gh alias set r "repo"

# Now use shortcuts
gh co 123      # instead of gh pr checkout 123
gh i list      # instead of gh issue list
gh r view      # instead of gh repo view

Configuration

# Set default editor
gh config set editor vim

# Set default repository
gh repo set-default owner/repo

# Set git protocol
gh config set git_protocol ssh

# View all config
gh config list

Essential Workflow Examples

Daily PR Workflow

# 1. Create feature branch
git checkout -b feature/new-feature

# 2. Make changes and commit
git add .
git commit -m "Add new feature"

# 3. Push and create PR
git push -u origin feature/new-feature
gh pr create --title "Add new feature" --reviewer owner

# 4. Check PR status
gh pr checks

# 5. After review, merge
gh pr merge --squash --delete-branch

Issue Triage Workflow

# 1. List open issues
gh issue list --state open --label "needs-triage"

# 2. View issue details
gh issue view 123

# 3. Add labels and assign
gh issue edit 123 --add-label "bug" --add-assignee @me

# 4. If duplicate, close and link
gh issue close 123 --comment "Duplicate of #456" --duplicate 456

Release Workflow

# 1. Create release branch
git checkout -b release/v1.2.0
git commit -m "Bump version"

# 2. Create tag and push
git tag v1.2.0
git push origin v1.2.0

# 3. Create GitHub release
gh release create v1.2.0 --title "Release v1.2.0" --notes-file CHANGELOG.md

# 4. Upload binaries
gh release upload v1.2.0 ./dist/myapp-darwin-amd64
gh release upload v1.2.0 ./dist/myapp-linux-amd64

GitHub CLI vs GitHub Web: When to Use Each

TaskGitHub CLIGitHub Web
---------------------------
Quick commitsβœ… Perfect❌ Too slow
Code reviewβœ… Great for terminal loversβœ… Better for complex diffs
Managing issuesβœ… Very efficientβœ… Good for non-technical users
Release managementβœ… Scriptable❌ Manual
First-time repo exploration❌ Limitedβœ… Better overview
Automation/CI/CDβœ… Excellent❌ Not applicable

Conclusion

The GitHub CLI is essential for developers who want to stay in the terminal and automate their GitHub workflows. These 20 commands cover 95% of what you'll do daily, from managing issues and PRs to creating releases and managing secrets.

Key Takeaways:

  • Use `gh auth login` to authenticate first
  • Use `--json` and `--jq` for scripting
  • Create aliases for frequently used commands
  • Use `--web` flag when you need the browser
  • Combine with `gh alias set` for personalized shortcuts

Start with the commands you use most often and gradually incorporate more. The CLI is especially powerful when combined with shell scripts and CI/CD pipelines.

---

Affiliate Disclosure: This article contains affiliate links. We may earn a commission if you purchase through our links at no extra cost to you.

Affiliate Disclosure: We may earn commissions from qualifying purchases via affiliate links.