my-notes

Using_GitHub_CLI

1 min read

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.



#github #cli #gh #commands

Built with mdgarden