| name | gh-cli |
| description | GitHub CLI (gh) comprehensive reference for repositories, issues, pull requests, Actions, projects, releases, gists, codespaces, organizations, extensions, and all GitHub operations from the command line. |
GitHub CLI (gh)
Comprehensive reference for GitHub CLI (gh) - work seamlessly with GitHub from the command line.
Version: 2.85.0 (current as of January 2026)
Prerequisites
Installation
brew install gh
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
sudo apt update
sudo apt install gh
winget install --id GitHub.cli
gh --version
Authentication
gh auth login
gh auth login --hostname enterprise.internal
gh auth login --with-token < mytoken.txt
gh auth status
gh auth switch --hostname github.com --user username
gh auth logout --hostname github.com --user username
Setup Git Integration
gh auth setup-git
gh auth token
gh auth refresh --scopes write:org,read:public_key
CLI Structure
gh # Root command
├── auth # Authentication
│ ├── login
│ ├── logout
│ ├── refresh
│ ├── setup-git
│ ├── status
│ ├── switch
│ └── token
├── browse # Open in browser
├── codespace # GitHub Codespaces
│ ├── code
│ ├── cp
│ ├── create
│ ├── delete
│ ├── edit
│ ├── jupyter
│ ├── list
│ ├── logs
│ ├── ports
│ ├── rebuild
│ ├── ssh
│ ├── stop
│ └── view
├── gist # Gists
│ ├── clone
│ ├── create
│ ├── delete
│ ├── edit
│ ├── list
│ ├── rename
│ └── view
├── issue # Issues
│ ├── create
│ ├── list
│ ├── status
│ ├── close
│ ├── comment
│ ├── delete
│ ├── develop
│ ├── edit
│ ├── lock
│ ├── pin
│ ├── reopen
│ ├── transfer
│ ├── unlock
│ └── view
├── org # Organizations
│ └── list
├── pr # Pull Requests
│ ├── create
│ ├── list
│ ├── status
│ ├── checkout
│ ├── checks
│ ├── close
│ ├── comment
│ ├── diff
│ ├── edit
│ ├── lock
│ ├── merge
│ ├── ready
│ ├── reopen
│ ├── revert
│ ├── review
│ ├── unlock
│ ├── update-branch
│ └── view
├── project # Projects
│ ├── close
│ ├── copy
│ ├── create
│ ├── delete
│ ├── edit
│ ├── field-create
│ ├── field-delete
│ ├── field-list
│ ├── item-add
│ ├── item-archive
│ ├── item-create
│ ├── item-delete
│ ├── item-edit
│ ├── item-list
│ ├── link
│ ├── list
│ ├── mark-template
│ ├── unlink
│ └── view
├── release # Releases
│ ├── create
│ ├── list
│ ├── delete
│ ├── delete-asset
│ ├── download
│ ├── edit
│ ├── upload
│ ├── verify
│ ├── verify-asset
│ └── view
├── repo # Repositories
│ ├── create
│ ├── list
│ ├── archive
│ ├── autolink
│ ├── clone
│ ├── delete
│ ├── deploy-key
│ ├── edit
│ ├── fork
│ ├── gitignore
│ ├── license
│ ├── rename
│ ├── set-default
│ ├── sync
│ ├── unarchive
│ └── view
├── cache # Actions caches
│ ├── delete
│ └── list
├── run # Workflow runs
│ ├── cancel
│ ├── delete
│ ├── download
│ ├── list
│ ├── rerun
│ ├── view
│ └── watch
├── workflow # Workflows
│ ├── disable
│ ├── enable
│ ├── list
│ ├── run
│ └── view
├── agent-task # Agent tasks
├── alias # Command aliases
│ ├── delete
│ ├── import
│ ├── list
│ └── set
├── api # API requests
├── attestation # Artifact attestations
│ ├── download
│ ├── trusted-root
│ └── verify
├── completion # Shell completion
├── config # Configuration
│ ├── clear-cache
│ ├── get
│ ├── list
│ └── set
├── extension # Extensions
│ ├── browse
│ ├── create
│ ├── exec
│ ├── install
│ ├── list
│ ├── remove
│ ├── search
│ └── upgrade
├── gpg-key # GPG keys
│ ├── add
│ ├── delete
│ └── list
├── label # Labels
│ ├── clone
│ ├── create
│ ├── delete
│ ├── edit
│ └── list
├── preview # Preview features
├── ruleset # Rulesets
│ ├── check
│ ├── list
│ └── view
├── search # Search
│ ├── code
│ ├── commits
│ ├── issues
│ ├── prs
│ └── repos
├── secret # Secrets
│ ├── delete
│ ├── list
│ └── set
├── ssh-key # SSH keys
│ ├── add
│ ├── delete
│ └── list
├── status # Status overview
└── variable # Variables
├── delete
├── get
├── list
└── set
Configuration
Global Configuration
gh config list
gh config list git_protocol
gh config get editor
gh config set editor vim
gh config set git_protocol ssh
gh config set prompt disabled
gh config set pager "less -R"
gh config clear-cache
Environment Variables
export GH_TOKEN=ghp_xxxxxxxxxxxx
export GH_HOST=github.com
export GH_PROMPT_DISABLED=true
export GH_EDITOR=vim
export GH_PAGER=less
export GH_TIMEOUT=30
export GH_REPO=owner/repo
export GH_ENTERPRISE_HOSTNAME=hostname
Authentication (gh auth)
Login
gh auth login
gh auth login --web
gh auth login --web --clipboard
gh auth login --git-protocol ssh
gh auth login --hostname enterprise.internal
gh auth login --with-token < token.txt
gh auth login --insecure-storage
Status
gh auth status
gh auth status --active
gh auth status --hostname github.com
gh auth status --show-token
gh auth status --json hosts
gh auth status --json hosts --jq '.hosts | add'
Switch Accounts
gh auth switch
gh auth switch --hostname github.com --user monalisa
Token
gh auth token
gh auth token --hostname github.com --user monalisa
Refresh
gh auth refresh
gh auth refresh --scopes write:org,read:public_key
gh auth refresh --remove-scopes delete_repo
gh auth refresh --reset-scopes
gh auth refresh --clipboard
Setup Git
gh auth setup-git
gh auth setup-git --hostname enterprise.internal
gh auth setup-git --hostname enterprise.internal --force
Browse (gh browse)
gh browse
gh browse script/
gh browse main.go:312
gh browse 123
gh browse 77507cd94ccafcf568f8560cfecde965fcfa63
gh browse main.go --branch bug-fix
gh browse --repo owner/repo
gh browse --actions
gh browse --projects
gh browse --releases
gh browse --settings
gh browse --wiki
gh browse --no-browser
Repositories (gh repo)
Create Repository
gh repo create my-repo
gh repo create my-repo --description "My awesome project"
gh repo create my-repo --public
gh repo create my-repo --private
gh repo create my-repo --homepage https://example.com
gh repo create my-repo --license mit
gh repo create my-repo --gitignore python
gh repo create my-repo --template
gh repo create org/my-repo
gh repo create my-repo --source=.
gh repo create my-repo --disable-issues
gh repo create my-repo --disable-wiki
Clone Repository
gh repo clone owner/repo
gh repo clone owner/repo my-directory
gh repo clone owner/repo --branch develop
List Repositories
gh repo list
gh repo list owner
gh repo list --limit 50
gh repo list --public
gh repo list --source
gh repo list --json name,visibility,owner
gh repo list --limit 100 | tail -n +2
gh repo list --json name --jq '.[].name'
View Repository
gh repo view
gh repo view owner/repo
gh repo view --json name,description,defaultBranchRef
gh repo view --web
Edit Repository
gh repo edit --description "New description"
gh repo edit --homepage https://example.com
gh repo edit --visibility private
gh repo edit --visibility public
gh repo edit --enable-issues
gh repo edit --disable-issues
gh repo edit --enable-wiki
gh repo edit --disable-wiki
gh repo edit --enable-projects
gh repo edit --disable-projects
gh repo edit --default-branch main
gh repo rename new-name
gh repo archive
gh repo unarchive
Delete Repository
gh repo delete owner/repo
gh repo delete owner/repo --yes
Fork Repository
gh repo fork owner/repo
gh repo fork owner/repo --org org-name
gh repo fork owner/repo --clone
gh repo fork owner/repo --remote-name upstream
Sync Fork
gh repo sync
gh repo sync --branch feature
gh repo sync --force
Set Default Repository
gh repo set-default
gh repo set-default owner/repo
gh repo set-default --unset
Repository Autolinks
gh repo autolink list
gh repo autolink add \
--key-prefix JIRA- \
--url-template https://jira.example.com/browse/<num>
gh repo autolink delete 12345
Repository Deploy Keys
gh repo deploy-key list
gh repo deploy-key add ~/.ssh/id_rsa.pub \
--title "Production server" \
--read-only
gh repo deploy-key delete 12345
Gitignore and License
gh repo gitignore
gh repo license mit
gh repo license mit --fullname "John Doe"
Issues (gh issue)
Create Issue
gh issue create
gh issue create --title "Bug: Login not working"
gh issue create \
--title "Bug: Login not working" \
--body "Steps to reproduce..."
gh issue create --body-file issue.md
gh issue create --title "Fix bug" --labels bug,high-priority
gh issue create --title "Fix bug" --assignee user1,user2
gh issue create --repo owner/repo --title "Issue title"
gh issue create --web
List Issues
gh issue list
gh issue list --state all
gh issue list --state closed
gh issue list --limit 50
gh issue list --assignee username
gh issue list --assignee @me
gh issue list --labels bug,enhancement
gh issue list --milestone "v1.0"
gh issue list --search "is:open is:issue label:bug"
gh issue list --json number,title,state,author
gh issue list --json number,title,labels --jq '.[] | [.number, .title, .labels[].name] | @tsv'
gh issue list --json number,title,comments --jq '.[] | [.number, .title, .comments]'
gh issue list --sort created --order desc
View Issue
gh issue view 123
gh issue view 123 --comments
gh issue view 123 --web
gh issue view 123 --json title,body,state,labels,comments
gh issue view 123 --json title --jq '.title'
Edit Issue
gh issue edit 123
gh issue edit 123 --title "New title"
gh issue edit 123 --body "New description"
gh issue edit 123 --add-label bug,high-priority
gh issue edit 123 --remove-label stale
gh issue edit 123 --add-assignee user1,user2
gh issue edit 123 --remove-assignee user1
gh issue edit 123 --milestone "v1.0"
Close/Reopen Issue
gh issue close 123
gh issue close 123 --comment "Fixed in PR #456"
gh issue reopen 123
Comment on Issue
gh issue comment 123 --body "This looks good!"
gh issue comment 123 --edit 456789 --body "Updated comment"
gh issue comment 123 --delete 456789
Issue Status
gh issue status
gh issue status --repo owner/repo
Pin/Unpin Issues
gh issue pin 123
gh issue unpin 123
Lock/Unlock Issue
gh issue lock 123
gh issue lock 123 --reason off-topic
gh issue unlock 123
Transfer Issue
gh issue transfer 123 --repo owner/new-repo
Delete Issue
gh issue delete 123
gh issue delete 123 --yes
Develop Issue (Draft PR)
gh issue develop 123
gh issue develop 123 --branch fix/issue-123
gh issue develop 123 --base main
Pull Requests (gh pr)
Create Pull Request
gh pr create
gh pr create --title "Feature: Add new functionality"
gh pr create \
--title "Feature: Add new functionality" \
--body "This PR adds..."
gh pr create --body-file .github/PULL_REQUEST_TEMPLATE.md
gh pr create --base main
gh pr create --head feature-branch
gh pr create --draft
gh pr create --assignee user1,user2
gh pr create --reviewer user1,user2
gh pr create --labels enhancement,feature
gh pr create --issue 123
gh pr create --repo owner/repo
gh pr create --web
List Pull Requests
gh pr list
gh pr list --state all
gh pr list --state merged
gh pr list --state closed
gh pr list --head feature-branch
gh pr list --base main
gh pr list --author username
gh pr list --author @me
gh pr list --assignee username
gh pr list --labels bug,enhancement
gh pr list --limit 50
gh pr list --search "is:open is:pr label:review-required"
gh pr list --json number,title,state,author,headRefName
gh pr list --json number,title,statusCheckRollup --jq '.[] | [.number, .title, .statusCheckRollup[]?.status]'
gh pr list --sort created --order desc
View Pull Request
gh pr view 123
gh pr view 123 --comments
gh pr view 123 --web
gh pr view 123 --json title,body,state,author,commits,files
gh pr view 123 --json files --jq '.files[].path'
gh pr view 123 --json title,state --jq '"\(.title): \(.state)"'
Checkout Pull Request
gh pr checkout 123
gh pr checkout 123 --branch name-123
gh pr checkout 123 --force
Diff Pull Request
gh pr diff 123
gh pr diff 123 --color always
gh pr diff 123 > pr-123.patch
gh pr diff 123 --name-only
Merge Pull Request
gh pr merge 123
gh pr merge 123 --merge
gh pr merge 123 --squash
gh pr merge 123 --rebase
gh pr merge 123 --delete-branch
gh pr merge 123 --subject "Merge PR #123" --body "Merging feature"
gh pr merge 123 --admin
gh pr merge 123 --admin
Close Pull Request
gh pr close 123
gh pr close 123 --comment "Closing due to..."
Reopen Pull Request
gh pr reopen 123
Edit Pull Request
gh pr edit 123
gh pr edit 123 --title "New title"
gh pr edit 123 --body "New description"
gh pr edit 123 --add-label bug,enhancement
gh pr edit 123 --remove-label stale
gh pr edit 123 --add-assignee user1,user2
gh pr edit 123 --remove-assignee user1
gh pr edit 123 --add-reviewer user1,user2
gh pr edit 123 --remove-reviewer user1
gh pr edit 123 --ready
Ready for Review
gh pr ready 123
Pull Request Checks
gh pr checks 123
gh pr checks 123 --watch
gh pr checks 123 --watch --interval 5
Comment on Pull Request
gh pr comment 123 --body "Looks good!"
gh pr comment 123 --body "Fix this" \
--repo owner/repo \
--head-owner owner --head-branch feature
gh pr comment 123 --edit 456789 --body "Updated"
gh pr comment 123 --delete 456789
Review Pull Request
gh pr review 123
gh pr review 123 --approve --body "LGTM!"
gh pr review 123 --request-changes \
--body "Please fix these issues"
gh pr review 123 --comment --body "Some thoughts..."
gh pr review 123 --dismiss
Update Branch
gh pr update-branch 123
gh pr update-branch 123 --force
gh pr update-branch 123 --merge
Lock/Unlock Pull Request
gh pr lock 123
gh pr lock 123 --reason off-topic
gh pr unlock 123
Revert Pull Request
gh pr revert 123
gh pr revert 123 --branch revert-pr-123
Pull Request Status
gh pr status
gh pr status --repo owner/repo
GitHub Actions
Workflow Runs (gh run)
gh run list
gh run list --workflow "ci.yml"
gh run list --branch main
gh run list --limit 20
gh run list --json databaseId,status,conclusion,headBranch
gh run view 123456789
gh run view 123456789 --log
gh run view 123456789 --job 987654321
gh run view 123456789 --web
gh run watch 123456789
gh run watch 123456789 --interval 5
gh run rerun 123456789
gh run rerun 123456789 --job 987654321
gh run cancel 123456789
gh run delete 123456789
gh run download 123456789
gh run download 123456789 --name build
gh run download 123456789 --dir ./artifacts
Workflows (gh workflow)
gh workflow list
gh workflow view ci.yml
gh workflow view ci.yml --yaml
gh workflow view ci.yml --web
gh workflow enable ci.yml
gh workflow disable ci.yml
gh workflow run ci.yml
gh workflow run ci.yml \
--raw-field \
version="1.0.0" \
environment="production"
gh workflow run ci.yml --ref develop
Action Caches (gh cache)
gh cache list
gh cache list --branch main
gh cache list --limit 50
gh cache delete 123456789
gh cache delete --all
Action Secrets (gh secret)
gh secret list
gh secret set MY_SECRET
echo "$MY_SECRET" | gh secret set MY_SECRET
gh secret set MY_SECRET --env production
gh secret set MY_SECRET --org orgname
gh secret delete MY_SECRET
gh secret delete MY_SECRET --env production
Action Variables (gh variable)
gh variable list
gh variable set MY_VAR "some-value"
gh variable set MY_VAR "value" --env production
gh variable set MY_VAR "value" --org orgname
gh variable get MY_VAR
gh variable delete MY_VAR
gh variable delete MY_VAR --env production
Projects (gh project)
gh project list
gh project list --owner owner
gh project list --open
gh project view 123
gh project view 123 --format json
gh project create --title "My Project"
gh project create --title "Project" --org orgname
gh project create --title "Project" --readme "Description here"
gh project edit 123 --title "New Title"
gh project delete 123
gh project close 123
gh project copy 123 --owner target-owner --title "Copy"
gh project mark-template 123
gh project field-list 123
gh project field-create 123 --title "Status" --datatype single_select
gh project field-delete 123 --id 456
gh project item-list 123
gh project item-create 123 --title "New item"
gh project item-add 123 --owner-owner --repo repo --issue 456
gh project item-edit 123 --id 456 --title "Updated title"
gh project item-delete 123 --id 456
gh project item-archive 123 --id 456
gh project link 123 --id 456 --link-id 789
gh project unlink 123 --id 456 --link-id 789
gh project view 123 --web
Releases (gh release)
gh release list
gh release view
gh release view v1.0.0
gh release view v1.0.0 --web
gh release create v1.0.0 \
--notes "Release notes here"
gh release create v1.0.0 --notes-file notes.md
gh release create v1.0.0 --target main
gh release create v1.0.0 --draft
gh release create v1.0.0 --prerelease
gh release create v1.0.0 --title "Version 1.0.0"
gh release upload v1.0.0 ./file.tar.gz
gh release upload v1.0.0 ./file1.tar.gz ./file2.tar.gz
gh release upload v1.0.0 ./file.tar.gz --casing
gh release delete v1.0.0
gh release delete v1.0.0 --yes
gh release delete-asset v1.0.0 file.tar.gz
gh release download v1.0.0
gh release download v1.0.0 --pattern "*.tar.gz"
gh release download v1.0.0 --dir ./downloads
gh release download v1.0.0 --archive zip
gh release edit v1.0.0 --notes "Updated notes"
gh release verify v1.0.0
gh release verify-asset v1.0.0 file.tar.gz
Gists (gh gist)
gh gist list
gh gist list --public
gh gist list --limit 20
gh gist view abc123
gh gist view abc123 --files
gh gist create script.py
gh gist create script.py --desc "My script"
gh gist create script.py --public
gh gist create file1.py file2.py
echo "print('hello')" | gh gist create
gh gist edit abc123
gh gist delete abc123
gh gist rename abc123 --filename old.py new.py
gh gist clone abc123
gh gist clone abc123 my-directory
Codespaces (gh codespace)
gh codespace list
gh codespace create
gh codespace create --repo owner/repo
gh codespace create --branch develop
gh codespace create --machine premiumLinux
gh codespace view
gh codespace ssh
gh codespace ssh --command "cd /workspaces && ls"
gh codespace code
gh codespace code --codec
gh codespace code --path /workspaces/repo
gh codespace stop
gh codespace delete
gh codespace logs
--tail 100
gh codespace ports
gh codespace cp 8080:8080
gh codespace rebuild
gh codespace edit --machine standardLinux
gh codespace jupyter
gh codespace cp file.txt :/workspaces/file.txt
gh codespace cp :/workspaces/file.txt ./file.txt
Organizations (gh org)
gh org list
gh org list --user username
gh org list --json login,name,description
gh org view orgname
gh org view orgname --json members --jq '.members[] | .login'
Search (gh search)
gh search code "TODO"
gh search code "TODO" --repo owner/repo
gh search commits "fix bug"
gh search issues "label:bug state:open"
gh search prs "is:open is:pr review:required"
gh search repos "stars:>1000 language:python"
gh search repos "topic:api" --limit 50
gh search repos "stars:>100" --json name,description,stargazers
gh search repos "language:rust" --order desc --sort stars
gh search code "import" --extension py
gh search prs "is:open" --web
Labels (gh label)
gh label list
gh label create bug --color "d73a4a" --description "Something isn't working"
gh label create enhancement --color "#a2eeef"
gh label edit bug --name "bug-report" --color "ff0000"
gh label delete bug
gh label clone owner/repo
gh label clone owner/repo --repo target/repo
SSH Keys (gh ssh-key)
gh ssh-key list
gh ssh-key add ~/.ssh/id_rsa.pub --title "My laptop"
gh ssh-key add ~/.ssh/id_ed25519.pub --type "authentication"
gh ssh-key delete 12345
gh ssh-key delete --title "My laptop"
GPG Keys (gh gpg-key)
gh gpg-key list
gh gpg-key add ~/.ssh/id_rsa.pub
gh gpg-key delete 12345
gh gpg-key delete ABCD1234
Status (gh status)
gh status
gh status --repo owner/repo
gh status --json
Configuration (gh config)
gh config list
gh config get editor
gh config set editor vim
gh config set git_protocol ssh
gh config clear-cache
gh config set prompt disabled
gh config set prompt enabled
Extensions (gh extension)
gh extension list
gh extension search github
gh extension install owner/extension-repo
gh extension install owner/extension-repo --branch develop
gh extension upgrade extension-name
gh extension remove extension-name
gh extension create my-extension
gh extension browse
gh extension exec my-extension --arg value
Aliases (gh alias)
gh alias list
gh alias set prview 'pr view --web'
gh alias set co 'pr checkout' --shell
gh alias delete prview
gh alias import ./aliases.sh
API Requests (gh api)
gh api /user
gh api --method POST /repos/owner/repo/issues \
--field title="Issue title" \
--field body="Issue body"
gh api /user \
--header "Accept: application/vnd.github.v3+json"
gh api /user/repos --paginate
gh api /user --raw
gh api /user --include
gh api /user --silent
gh api --input request.json
gh api /user --jq '.login'
gh api /repos/owner/repo --jq '.stargazers_count'
gh api /user --hostname enterprise.internal
gh api graphql \
-f query='
{
viewer {
login
repositories(first: 5) {
nodes {
name
}
}
}
}'
Rulesets (gh ruleset)
gh ruleset list
gh ruleset view 123
gh ruleset check --branch feature
gh ruleset check --repo owner/repo --branch main
Attestations (gh attestation)
gh attestation download owner/repo \
--artifact-id 123456
gh attestation verify owner/repo
gh attestation trusted-root
Completion (gh completion)
gh completion -s bash > ~/.gh-complete.bash
gh completion -s zsh > ~/.gh-complete.zsh
gh completion -s fish > ~/.gh-complete.fish
gh completion -s powershell > ~/.gh-complete.ps1
gh completion --shell=bash
gh completion --shell=zsh
Preview (gh preview)
gh preview
gh preview prompter
Agent Tasks (gh agent-task)
gh agent-task list
gh agent-task view 123
gh agent-task create --description "My task"
Global Flags
| Flag | Description |
|---|
--help / -h | Show help for command |
--version | Show gh version |
--repo [HOST/]OWNER/REPO | Select another repository |
--hostname HOST | GitHub hostname |
--jq EXPRESSION | Filter JSON output |
--json FIELDS | Output JSON with specified fields |
--template STRING | Format JSON using Go template |
--web | Open in browser |
--paginate | Make additional API calls |
--verbose | Show verbose output |
--debug | Show debug output |
--timeout SECONDS | Maximum API request duration |
--cache CACHE | Cache control (default, force, bypass) |
Output Formatting
JSON Output
gh repo view --json name,description
gh repo view --json owner,name --jq '.owner.login + "/" + .name'
gh pr list --json number,title --jq '.[] | select(.number > 100)'
gh issue list --json number,title,labels \
--jq '.[] | {number, title: .title, tags: [.labels[].name]}'
Template Output
gh repo view \
--template '{{.name}}: {{.description}}'
gh pr view 123 \
--template 'Title: {{.title}}
Author: {{.author.login}}
State: {{.state}}
'
Common Workflows
Create PR from Issue
gh issue develop 123 --branch feature/issue-123
git add .
git commit -m "Fix issue #123"
git push
gh pr create --title "Fix #123" --body "Closes #123"
Bulk Operations
gh issue list --search "label:stale" \
--json number \
--jq '.[].number' | \
xargs -I {} gh issue close {} --comment "Closing as stale"
gh pr list --search "review:required" \
--json number \
--jq '.[].number' | \
xargs -I {} gh pr edit {} --add-label needs-review
Repository Setup Workflow
gh repo create my-project --public \
--description "My awesome project" \
--clone \
--gitignore python \
--license mit
cd my-project
git checkout -b develop
git push -u origin develop
gh label create bug --color "d73a4a" --description "Bug report"
gh label create enhancement --color "a2eeef" --description "Feature request"
gh label create documentation --color "0075ca" --description "Documentation"
CI/CD Workflow
RUN_ID=$(gh workflow run ci.yml --ref main --jq '.databaseId')
gh run watch "$RUN_ID"
gh run download "$RUN_ID" --dir ./artifacts
Fork Sync Workflow
gh repo fork original/repo --clone
cd repo
git remote add upstream https://github.com/original/repo.git
gh repo sync
git fetch upstream
git checkout main
git merge upstream/main
git push origin main
Environment Setup
Shell Integration
eval "$(gh completion -s bash)"
alias gs='gh status'
alias gpr='gh pr view --web'
alias gir='gh issue view --web'
alias gco='gh pr checkout'
Git Configuration
gh auth setup-git
git config --global credential.helper 'gh !gh auth setup-git'
git config --global credential.helper github
Best Practices
-
Authentication: Use environment variables for automation
export GH_TOKEN=$(gh auth token)
-
Default Repository: Set default to avoid repetition
gh repo set-default owner/repo
-
JSON Parsing: Use jq for complex data extraction
gh pr list --json number,title --jq '.[] | select(.title | contains("fix"))'
-
Pagination: Use --paginate for large result sets
gh issue list --state all --paginate
-
Caching: Use cache control for frequently accessed data
gh api /user --cache force
Getting Help
gh --help
gh pr --help
gh issue create --help
gh help formatting
gh help environment
gh help exit-codes
gh help accessibility
References