GitHub CLI (gh) - Complete Guide for Daily Use Updated for 2025 | For Termux Users
Table of Contents Initial Setup Authentication Repository Commands Issue Management Pull Requests GitHub Actions & Workflows Gist Management Release Management GitHub Copilot (CLI) Advanced Tips & Tricks Initial Setup Check Installation gh --version View Help gh help gh <command> --help gh <command> <subcommand> --help Authentication Login to GitHub # Interactive login (recommended) gh auth login # Login with token gh auth login --with-token < token.txt # Login to GitHub Enterprise gh auth login --hostname github.enterprise.com Check Authentication Status gh auth status # Check for specific hostname gh auth status --hostname github.com Switch Accounts gh auth switch # Switch to specific account gh auth switch --user username Logout gh auth logout # Logout from specific hostname gh auth logout --hostname github.com Get Authentication Token gh auth token Repository Commands Create Repository Create a New Repository # Create public repository gh repo create my-project --public # Create private repository gh repo create my-project --private # Create with description gh repo create my-project --description "My awesome project" --public # Create from current directory gh repo create --source=. --private --push # Create with specific gitignore and license gh repo create my-project --gitignore Node --license MIT --public Interactive Creation gh repo create # Follow the prompts Clone Repository # Clone your repository gh repo clone username/repo-name # Clone to specific directory gh repo clone username/repo-name target-directory # Clone with all submodules gh repo clone username/repo-name -- --recurse-submodules Fork Repository # Fork a repository gh repo fork owner/repo-name # Fork and clone gh repo fork owner/repo-name --clone # Fork with custom name gh repo fork owner/repo-name --fork-name my-fork View Repository # View repository in browser gh repo view # View specific repository gh repo view owner/repo-name # View in terminal (README) gh repo view owner/repo-name --web=false # View in browser gh repo view owner/repo-name --web Repository Information # List your repositories gh repo list # List organization repositories gh repo list organization-name # List with filters gh repo list --limit 50 --language python --public # List archived repositories gh repo list --archived Repository Settings # Archive repository gh repo archive owner/repo-name # Unarchive repository gh repo unarchive owner/repo-name # Delete repository (careful!) gh repo delete owner/repo-name --yes # Rename repository gh repo rename new-name # Edit repository settings gh repo edit --description "New description" --homepage "https://example.com" # Enable/disable features gh repo edit --enable-wiki gh repo edit --disable-issues gh repo edit --enable-projects Sync Fork # Sync your fork with upstream gh repo sync owner/repo-name # Sync current repository gh repo sync Issue Management Create Issues # Interactive issue creation gh issue create # Create with title and body gh issue create --title "Bug: Something broke" --body "Description here" # Create from file gh issue create --title "Feature Request" --body-file issue.md # Assign issue to yourself gh issue create --title "New task" --assignee @me # Create with labels gh issue create --title "Bug report" --label bug,urgent # Create with milestone gh issue create --title "Task" --milestone "v1.0" # Assign to specific user gh issue create --title "Task" --assignee username # Create with project gh issue create --title "Feature" --project "Roadmap" List Issues # List open issues gh issue list # List all issues (including closed) gh issue list --state all # List with filters gh issue list --label bug --assignee @me gh issue list --author username gh issue list --mention @me # List with limit gh issue list --limit 50 # Search issues gh issue list --search "bug in:title" # List by state gh issue list --state closed View Issue # View issue in browser gh issue view 123 # View in terminal gh issue view 123 --web=false # View with comments gh issue view 123 --comments Edit Issue # Edit issue interactively gh issue edit 123 # Update title gh issue edit 123 --title "New title" # Add/remove labels gh issue edit 123 --add-label "bug,urgent" gh issue edit 123 --remove-label "wontfix" # Change assignee gh issue edit 123 --add-assignee username gh issue edit 123 --remove-assignee username # Update milestone gh issue edit 123 --milestone "v2.0" # Update body gh issue edit 123 --body "Updated description" Comment on Issues # Add comment gh issue comment 123 --body "This is a comment" # Add comment from file gh issue comment 123 --body-file comment.md # Edit your last comment gh issue comment 123 --edit-last Close/Reopen Issues # Close issue gh issue close 123 # Close with comment gh issue close 123 --comment "Fixed in #124" # Close as completed gh issue close 123 --reason completed # Close as not planned gh issue close 123 --reason "not planned" # Reopen issue gh issue reopen 123 # Reopen with comment gh issue reopen 123 --comment "Need to revisit this" Pin/Unpin Issues # Pin issue gh issue pin 123 # Unpin issue gh issue unpin 123 Transfer Issue # Transfer to another repository gh issue transfer 123 owner/destination-repo Issue Status # Check issue status gh issue status # View issues assigned to you gh issue status --assignee @me Pull Requests Create Pull Request # Interactive PR creation gh pr create # Create with title and body gh pr create --title "Add new feature" --body "Description" # Create from file gh pr create --title "Feature" --body-file pr.md # Create draft PR gh pr create --draft --title "WIP: Feature" # Create with reviewers gh pr create --title "Feature" --reviewer user1,user2 # Create with assignees gh pr create --title "Feature" --assignee @me # Create with labels gh pr create --title "Feature" --label enhancement,documentation # Create with milestone gh pr create --title "Feature" --milestone "v1.0" # Create to specific branch gh pr create --base develop --head feature-branch # Fill with commits gh pr create --fill # Auto-fill from commits and title from branch gh pr create --fill-first # Create and open in browser gh pr create --web List Pull Requests # List open PRs gh pr list # List all PRs gh pr list --state all # List by author gh pr list --author username gh pr list --author @me # List with filters gh pr list --label bug --assignee @me # List by base branch gh pr list --base main # Search PRs gh pr list --search "fix in:title" # List draft PRs gh pr list --draft # List ready for review gh pr list --search "is:pr is:open review:required" View Pull Request # View PR in browser gh pr view 123 # View in terminal gh pr view 123 --web=false # View with comments gh pr view 123 --comments # View diff gh pr diff 123 # View with JSON output gh pr view 123 --json title,body,state Checkout Pull Request # Checkout PR branch locally gh pr checkout 123 # Checkout by branch name gh pr checkout feature-branch # Force checkout (discard local changes) gh pr checkout 123 --force Review Pull Request # Start interactive review gh pr review 123 # Approve PR gh pr review 123 --approve # Request changes gh pr review 123 --request-changes --body "Please fix the typo" # Comment on PR gh pr review 123 --comment --body "Looks good overall" # Approve with comment gh pr review 123 --approve --body "LGTM!" Comment on Pull Request # Add comment gh pr comment 123 --body "Great work!" # Add comment from file gh pr comment 123 --body-file comment.md Edit Pull Request # Edit PR interactively gh pr edit 123 # Update title gh pr edit 123 --title "New title" # Update body gh pr edit 123 --body "Updated description" # Add/remove labels gh pr edit 123 --add-label "ready-to-merge" gh pr edit 123 --remove-label "wip" # Add/remove reviewers gh pr edit 123 --add-reviewer user1,user2 gh pr edit 123 --remove-reviewer user3 # Add/remove assignees gh pr edit 123 --add-assignee @me gh pr edit 123 --remove-assignee username # Update milestone gh pr edit 123 --milestone "v2.0" # Update base branch gh pr edit 123 --base develop # Convert to draft gh pr ready 123 --undo # Mark as ready for review gh pr ready 123 Merge Pull Request # Merge PR (default merge commit) gh pr merge 123 # Merge with squash gh pr merge 123 --squash # Merge with rebase gh pr merge 123 --rebase # Merge and delete branch gh pr merge 123 --delete-branch # Auto-merge when checks pass gh pr merge 123 --auto --squash # Merge with custom commit message gh pr merge 123 --subject "Custom message" --body "Details" # Disable auto-merge gh pr merge 123 --disable-auto Close/Reopen Pull Request # Close PR without merging gh pr close 123 # Close with comment gh pr close 123 --comment "Closing due to..." # Delete branch when closing gh pr close 123 --delete-branch # Reopen PR gh pr reopen 123 # Reopen with comment gh pr reopen 123 --comment "Reopening because..." Check PR Status # Check status of your PRs gh pr status # View checks for a PR gh pr checks 123 # Watch checks in real-time gh pr checks 123 --watch # View specific check details gh pr checks 123 --required GitHub Actions & Workflows List Workflows # List all workflows gh workflow list # List with status gh workflow list --all View Workflow # View workflow details gh workflow view workflow-name # View workflow in browser gh workflow view workflow-name --web # View workflow YAML gh workflow view workflow-name --yaml Run Workflow # Run workflow interactively gh workflow run # Run specific workflow gh workflow run workflow-name # Run with inputs gh workflow run workflow-name --field key=value # Run on specific branch gh workflow run workflow-name --ref branch-name # Run with raw parameters gh workflow run workflow-name --raw-field key=value Enable/Disable Workflow # Enable workflow gh workflow enable workflow-name # Disable workflow gh workflow disable workflow-name List Workflow Runs # List all runs gh run list # List for specific workflow gh run list --workflow workflow-name # List with filters gh run list --branch main --status success gh run list --event push gh run list --limit 50 # List all statuses gh run list --status completed gh run list --status failure gh run list --status in_progress View Run Details # View run in browser gh run view 123456 # View in terminal gh run view 123456 --web=false # View logs gh run view 123456 --log # View specific job logs gh run view 123456 --job=job-id --log # Exit with non-zero if run failed gh run view 123456 --exit-status Watch Run # Watch run progress gh run watch 123456 # Watch with exit status gh run watch 123456 --exit-status Rerun Workflow # Rerun entire workflow gh run rerun 123456 # Rerun only failed jobs gh run rerun 123456 --failed # Rerun with debug gh run rerun 123456 --debug Cancel Run # Cancel workflow run gh run cancel 123456 Download Run Artifacts # Download all artifacts gh run download 123456 # Download specific artifact gh run download 123456 --name artifact-name # Download to specific directory gh run download 123456 --dir ./downloads Delete Run # Delete workflow run gh run delete 123456 View Run Logs # View logs for latest run gh run view --log # View logs for specific run gh run view 123456 --log # View logs for specific job gh run view 123456 --log --job=job-name Gist Management Create Gist # Create gist from file gh gist create file.txt # Create multiple files gh gist create file1.txt file2.js # Create from stdin echo "Hello World" | gh gist create - # Create with description gh gist create file.txt --desc "My awesome gist" # Create public gist gh gist create file.txt --public # Create with filename gh gist create - --filename "hello.txt" < file.txt # Create and open in browser gh gist create file.txt --web List Gists # List your gists gh gist list # List with limit gh gist list --limit 50 # List public only gh gist list --public # List secret only gh gist list --secret View Gist # View gist in browser gh gist view gist-id # View in terminal gh gist view gist-id --raw # View specific file gh gist view gist-id --filename file.txt # View files list gh gist view gist-id --files Edit Gist # Edit gist file gh gist edit gist-id --filename file.txt # Add file to gist gh gist edit gist-id --add new-file.txt # Remove file from gist gh gist edit gist-id --remove old-file.txt # Update description gh gist edit gist-id --desc "Updated description" Clone Gist # Clone gist gh gist clone gist-id # Clone to specific directory gh gist clone gist-id target-dir Delete Gist # Delete gist gh gist delete gist-id Release Management Create Release # Interactive release creation gh release create # Create with tag gh release create v1.0.0 # Create with title and notes gh release create v1.0.0 --title "Version 1.0.0" --notes "Release notes" # Create from notes file gh release create v1.0.0 --notes-file CHANGELOG.md # Create draft release gh release create v1.0.0 --draft # Create pre-release gh release create v1.0.0 --prerelease # Create with assets gh release create v1.0.0 ./dist/*.zip # Generate notes automatically gh release create v1.0.0 --generate-notes # Create with specific target gh release create v1.0.0 --target main # Verify tag signature gh release create v1.0.0 --verify-tag List Releases # List all releases gh release list # List with limit gh release list --limit 20 # Exclude drafts gh release list --exclude-drafts # Exclude pre-releases gh release list --exclude-pre-releases View Release # View latest release gh release view # View specific release gh release view v1.0.0 # View in browser gh release view v1.0.0 --web # View with JSON output gh release view v1.0.0 --json tagName,name,assets Download Release Assets # Download all assets from latest release gh release download # Download from specific release gh release download v1.0.0 # Download specific asset gh release download v1.0.0 --pattern "*.zip" # Download to specific directory gh release download v1.0.0 --dir ./downloads # Skip existing files gh release download v1.0.0 --skip-existing # Download archive gh release download v1.0.0 --archive zip Edit Release # Edit release interactively gh release edit v1.0.0 # Update title gh release edit v1.0.0 --title "New Title" # Update notes gh release edit v1.0.0 --notes "Updated notes" # Mark as latest gh release edit v1.0.0 --latest # Mark as pre-release gh release edit v1.0.0 --prerelease # Convert draft to published gh release edit v1.0.0 --draft=false # Update tag gh release edit v1.0.0 --tag v1.0.1 Upload Release Assets # Upload assets to release gh release upload v1.0.0 ./dist/*.zip # Upload and overwrite existing gh release upload v1.0.0 app.zip --clobber Delete Release # Delete release gh release delete v1.0.0 # Delete with confirmation gh release delete v1.0.0 --yes # Delete and cleanup tag gh release delete v1.0.0 --cleanup-tag GitHub Copilot (CLI) Copilot Explain # Explain a command gh copilot explain "git rebase -i HEAD~3" # Explain in interactive mode gh copilot explain Copilot Suggest # Get command suggestions gh copilot suggest "list all running docker containers" # Suggest git command gh copilot suggest --target git "undo last commit" # Suggest GitHub CLI command gh copilot suggest --target gh "create a pull request" # Suggest shell command gh copilot suggest --target shell "find large files" Advanced Tips & Tricks Configuration View Configuration # View all configuration gh config list # Get specific value gh config get editor gh config get git_protocol Set Configuration # Set default editor gh config set editor vim gh config set editor "code --wait" # Set git protocol gh config set git_protocol ssh gh config set git_protocol https # Set browser gh config set browser firefox # Set default prompt behavior gh config set prompt enabled # Set preferred pager gh config set pager less Aliases List Aliases gh alias list Create Aliases # Simple alias gh alias set pv 'pr view' # Alias with parameters gh alias set bugs 'issue list --label=bug' # Shell alias gh alias set --shell igrep 'gh issue list --label="$1" | grep "$2"' # Complex aliases gh alias set prs 'pr list --state open --author @me' gh alias set co 'pr checkout' gh alias set merge 'pr merge --squash --delete-branch' Delete Alias gh alias delete pv Search Search Repositories # Search repositories gh search repos "machine learning" --language python # Search with stars filter gh search repos "web framework" --stars ">1000" # Search in specific organization gh search repos "react" --owner facebook # Limit results gh search repos "cli tool" --limit 10 # Search archived repos gh search repos "archived:true" # Search by topic gh search repos "topic:nodejs" Search Code # Search code gh search code "func main" --language go # Search in specific repository gh search code "authentication" --repo owner/repo # Search by filename gh search code --filename ".github/workflows/*.yml" # Search in path gh search code "import" --path "src/" Search Issues & PRs # Search issues gh search issues "bug" --repo owner/repo # Search PRs gh search prs "fix" --state open # Search by label gh search issues "label:bug" # Search by author gh search issues "author:username" # Search by assignee gh search issues "assignee:@me" # Complex search gh search issues "is:open label:bug created:>2024-01-01" Search Commits # Search commits gh search commits "fix bug" # Search in repository gh search commits "security" --repo owner/repo # Search by author gh search commits "author:username" # Search by committer gh search commits "committer:username" # Search with date range gh search commits "created:2024-01-01..2024-12-31" API Access Make API Calls # GET request gh api repos/:owner/:repo # GET with parameters gh api repos/:owner/:repo/issues --field state=open # POST request gh api repos/:owner/:repo/issues --method POST --field title="Bug report" # Paginate results gh api repos/:owner/:repo/issues --paginate # Use custom headers gh api repos/:owner/:repo --header "Accept: application/vnd.github.v3+json" # GraphQL query gh api graphql -f query='query { viewer { login } }' # Save response to file gh api repos/:owner/:repo > repo.json # Use JQ to parse gh api repos/:owner/:repo | jq '.stargazers_count' Extensions List Extensions gh extension list Install Extension # Install from repository gh extension install owner/gh-extension-name # Install from local path gh extension install . Upgrade Extensions # Upgrade all extensions gh extension upgrade --all # Upgrade specific extension gh extension upgrade extension-name Remove Extension gh extension remove extension-name Browse Extensions gh extension browse SSH Keys List SSH Keys gh ssh-key list Add SSH Key # Add from file gh ssh-key add ~/.ssh/id_ed25519.pub --title "My Laptop" # Add with stdin cat ~/.ssh/id_rsa.pub | gh ssh-key add --title "Work Desktop" Delete SSH Key gh ssh-key delete key-id GPG Keys List GPG Keys gh gpg-key list Add GPG Key # Add from file gh gpg-key add key.asc # Add with stdin gpg --armor --export key-id | gh gpg-key add Delete GPG Key gh gpg-key delete key-id Notifications List Notifications # List all notifications gh api notifications # List unread notifications gh api notifications --field all=false # Mark as read gh api notifications --method PUT Environment Variables Important environment variables for gh:
...