Using_GitHub_CLI
Using GitHub CLI
Command-line interface for GitHub.
π₯ Installation
macOS (Homebrew)
brew install gh
Install via Homebrew.
Windows (Winget)
winget install --id GitHub.cli
Install via Windows Package Manager.
Linux (Debian/Ubuntu)
sudo apt install gh
Install via apt.
π Authentication
Login
gh auth login
Interactive login to GitHub.
Login with Token
gh auth login --with-token < token.txt
Login using personal access token.
Check Status
gh auth status
Shows authentication status.
Logout
gh auth logout
Logs out of GitHub CLI.
π Repository Commands
Clone
gh repo clone owner/repo
Clones repository.
Create
gh repo create my-repo --public
Creates new repository.
Fork
gh repo fork owner/repo --clone
Forks and clones.
View
gh repo view
Shows current repo info.
π Pull Request Commands
Create PR
gh pr create
Creates pull request.
List PRs
gh pr list
Shows open PRs.
Checkout PR
gh pr checkout 123
Checks out PR locally.
View PR
gh pr view 123
Shows PR details.
Merge PR
gh pr merge 123 --squash
Squash merges PR.
Review PR
gh pr review 123 --approve
Approves PR.
π Issue Commands
Create Issue
gh issue create --title "Bug" --body "Description"
Creates issue.
List Issues
gh issue list
Shows open issues.
Close Issue
gh issue close 123
Closes issue.
π§ Workflow Commands
List Workflows
gh workflow list
Shows all workflows.
Run Workflow
gh workflow run ci.yml
Triggers workflow.
View Runs
gh run list
Shows workflow runs.
Watch Run
gh run watch
Live-watch running workflow.
π API Access
REST API Call
gh api repos/{owner}/{repo}
Makes API request.
GraphQL Query
gh api graphql -f query='{ viewer { login } }'
Makes GraphQL query.
βοΈ Configuration
Set Editor
gh config set editor "code --wait"
Sets default editor.
Set Protocol
gh config set git_protocol ssh
Uses SSH for cloning.
View Config
gh config list
Shows configuration.
π‘ Tips
Aliases
gh alias set co 'pr checkout'
Create shortcuts.
JSON Output
gh issue list --json number,title
Get JSON for scripting.
π Related
#github #cli #gh #commands