GitHub & GitHub CLI Cheat Sheet
gh brings pull requests, issues, Actions and releases into your terminal. Install with winget install GitHub.cli, brew install gh or sudo apt install gh.
On this page
Setup #
| Command | Action |
|---|---|
| Log in (browser or token) | |
| Check login | |
| Use gh as the Git credential helper |
Repositories #
| Command | Action |
|---|---|
| Create a new repo and clone it | |
| Publish the current folder as a new repo | |
| Clone | |
| Fork and clone | |
| Open the repo in the browser | |
| Open the current repo / file in the browser | |
| Your repos |
Pull Requests #
| Command | Action |
|---|---|
| Create a PR from the current branch (title/body from commits) | |
| Create as a draft | |
| Open PRs | |
| PRs relevant to you | |
| Check out PR #42 locally | |
| Open in the browser | |
| Show the diff | |
| CI status | |
Approve (--request-changes -b "..." to request changes) | |
| Squash-merge and clean up | |
| Mark a draft as ready |
Issues #
| Command | Action |
|---|---|
| New issue (interactive) | |
| Issues assigned to you | |
| Show an issue | |
| Close | |
| Create a branch linked to the issue |
Actions (CI/CD) #
| Command | Action |
|---|---|
| Recent workflow runs | |
| Follow a run live | |
| Logs of the failed steps | |
| Re-run the failed jobs | |
| Workflows | |
| Trigger a workflow manually | |
| Add a repository secret |
Releases & Gists #
| Command | Action |
|---|---|
| Release with automatic notes | |
| Attach files | |
| Download assets | |
| Share a snippet |
Misc #
| Command | Action |
|---|---|
| Search GitHub | |
| Call the REST API directly | |
| Create your own shortcut | |
| Add extensions |
GitHub Website Shortcuts #
| Key | Action |
|---|---|
? | Show all shortcuts |
/ or s | Search |
t | File finder in a repo |
. | Open the repo in the web editor (github.dev) |
y | Turn the URL into a permalink to this exact commit |
b | Blame view (on a file) |
l | Jump to a line (on a file) |
g c / g i / g p | Code / Issues / Pull requests tab |
Markdown Magic in Issues & PRs #
| Write | Effect |
|---|---|
Fixes #12 in a PR description | Closes issue 12 when the PR is merged |
@username | Mention someone |
- [ ] task | Checkbox |
> [!NOTE] / > [!WARNING] | Colored alert boxes |
| Drag an image in | Upload and embed |
gh authLog in to GitHub. gh auth subcommand [options]
| Subcommand / option | What it does |
|---|---|
login | Log in (browser or token, asks questions) |
login --web | Log in through the browser directly |
login --with-token < token.txt | Log in with a personal access token |
-h github.example.com | GitHub Enterprise host |
-s repo,workflow | Extra permission scopes |
status | Show which accounts are logged in |
logout | Log out |
refresh -s delete_repo | Add scopes to the current login |
setup-git | Use gh as Git's credential helper |
switch | Switch between logged-in accounts |
token | Print the current token |
gh repoWork with repositories. gh repo subcommand [options]
| Subcommand / option | What it does |
|---|---|
create name | New repo (--public, --private, --internal) |
create --source=. --push | Publish the current folder |
create name --clone | Create and clone it |
create --template owner/repo | Start from a template |
clone owner/repo [folder] | Clone |
fork owner/repo --clone | Fork and clone (adds upstream remote) |
view [--web] | Show the README / open in the browser |
list [owner] | Repos (--limit 100, --visibility private) |
edit --description "…" | Change settings (--visibility, --enable-issues…) |
sync | Update your fork from the original |
rename new-name | Rename |
archive / delete | Archive / ⚠ delete a repo |
set-default | Choose the default repo for gh in this folder |
gh browseOpen the repo (or a file, issue, PR) in the browser. gh browse [target] [options]
| Usage / option | What it does |
|---|---|
gh browse | Repository home page |
gh browse src/app.js:42 | A file at a line |
gh browse 123 | Issue or PR #123 |
-b branch | On a specific branch |
-s / -p / -w | Settings / projects / wiki |
-n | Print the URL instead of opening it |
gh prPull requests. gh pr subcommand [number] [options]
| Subcommand / option | What it does |
|---|---|
create | New PR from the current branch (asks questions) |
create --fill | Title and body from the commits |
create --draft / -B main / -r user | Draft / base branch / reviewer |
create --web | Finish in the browser |
list | Open PRs (--state merged, --author @me, --label bug) |
status | PRs relevant to you |
view 42 [--web] | Show a PR (--comments) |
checkout 42 | Check out a PR locally |
diff 42 | Show the diff |
checks 42 [--watch] | CI status |
review 42 --approve | Approve (--request-changes -b "…", --comment) |
comment 42 -b "Looks good" | Add a comment |
merge 42 --squash -d | Merge (--merge, --rebase), -d deletes the branch |
merge --auto | Merge automatically when checks pass |
ready / close / reopen | Mark ready / close / reopen |
edit 42 --add-label bug | Change title, labels, reviewers… |
gh issueIssues. gh issue subcommand [number] [options]
| Subcommand / option | What it does |
|---|---|
create | New issue (-t "title" -b "body", -l bug, -a @me) |
list | Open issues (--assignee @me, --label bug, --state closed) |
view 12 [--web] | Show an issue (--comments) |
status | Issues relevant to you |
comment 12 -b "…" | Comment |
close 12 / reopen 12 | Close / reopen (--reason "not planned") |
edit 12 --add-assignee @me | Change labels, assignees, milestone… |
develop 12 --checkout | Create a linked branch and check it out |
pin / transfer / delete | Pin / move to another repo / delete |
gh runGitHub Actions runs. gh run subcommand [id] [options]
| Subcommand / option | What it does |
|---|---|
list | Recent runs (-w deploy.yml, -b main, --status failure) |
view [id] | Summary (--log, --log-failed, --web) |
watch [id] | Follow a run live (--exit-status for scripts) |
rerun id | Run again (--failed = only failed jobs, --debug) |
cancel id | Stop a run |
download id | Download artifacts (-n name) |
delete id | Delete a run |
gh workflowGitHub Actions workflows. gh workflow subcommand [workflow] [options]
| Subcommand / option | What it does |
|---|---|
list | All workflows |
view deploy.yml | Recent runs of a workflow (--web) |
run deploy.yml | Trigger a workflow_dispatch workflow |
run deploy.yml -f env=prod | With inputs (--ref branch) |
enable / disable | Turn a workflow on / off |
gh secretSecrets for Actions, Codespaces and Dependabot. gh secret subcommand [name] [options]
| Subcommand / option | What it does |
|---|---|
set NAME | Set a secret (prompts for the value) |
set NAME < file / -b value | Value from a file / argument |
set -f .env | Set every secret in a dotenv file |
list | Names of the secrets |
delete NAME | Remove a secret |
--env production | Environment secret |
--org myorg --visibility all | Organisation secret |
--app codespaces | Secret for Codespaces / Dependabot |
gh releaseReleases. gh release subcommand [tag] [options]
| Subcommand / option | What it does |
|---|---|
create v1.0.0 | New release (creates the tag if needed) |
--generate-notes | Notes from merged PRs |
-n "notes" / -F notes.md | Notes text / file |
--draft / --prerelease / --latest | Release type |
create v1.0.0 dist/*.zip | Attach files while creating |
upload v1.0.0 file.zip | Add files (--clobber = overwrite) |
list / view v1.0.0 | List / show releases |
download v1.0.0 -p "*.zip" | Download assets |
edit / delete v1.0.0 | Change / delete (--cleanup-tag) |
gh gistGists (shared snippets). gh gist subcommand [options]
| Subcommand / option | What it does |
|---|---|
create file.js | New secret gist (--public, -d "description") |
create - | From standard input: cat x | gh gist create - |
list | Your gists |
view id | Show a gist (--raw, --web) |
edit id | Edit in your editor (-a file adds a file) |
clone id | Clone as a Git repo |
delete id | Delete |
gh searchSearch GitHub. gh search type query [options]
| Usage / option | What it does |
|---|---|
repos "astro components" | Repositories |
issues "memory leak" / prs | Issues / pull requests |
code "useEffect cleanup" | Code |
commits "fix typo" | Commits |
--language typescript | Filter by language |
--owner vercel | Filter by owner |
--sort stars --order desc | Sorting |
--limit 50 | Number of results |
--json name,url | JSON output |
--web | Open the search in the browser |
gh apiCall the GitHub REST or GraphQL API, already authenticated. gh api endpoint [options]
| Option | What it does |
|---|---|
repos/{owner}/{repo} | Placeholders filled from the current repo |
-X POST (--method) | HTTP method |
-f key=value | String field |
-F key=value | Typed field (numbers, @file) |
-H "Accept: …" | Header |
--paginate | Fetch all pages |
-q '.[].name' (--jq) | Filter the JSON |
-t '{{.name}}' | Go template output |
graphql -f query='…' | GraphQL query |
-i | Include response headers |
gh aliasYour own gh shortcuts. gh alias subcommand
| Usage | What it does |
|---|---|
set prc 'pr create --fill' | gh prc runs gh pr create --fill |
set --shell igrep 'gh issue list | grep "$1"' | Alias that runs shell commands |
list | All aliases |
delete prc | Remove one |
import aliases.yml | Load aliases from a file |
gh extensionalso: gh extAdd extra gh commands. gh extension subcommand
| Subcommand | What it does |
|---|---|
browse | Browse extensions interactively |
search word | Search extensions |
install owner/gh-name | Install |
list | Installed extensions |
upgrade --all | Update all |
remove name | Uninstall |
create name | Start your own extension |
Nothing on this sheet matches “”.