Getting Started with GitHub CLI (gh) / Chapter 1 — Getting Started with gh (lessons 1–4) / Lesson 1

What gh Is — GitHub from Your Terminal

Time needed: about 7 min (estimate)

☆ Read later

You can try the opening of this lesson without an account.

Bringing browser work into the terminal

GitHub CLI (the command is gh) is GitHub's official command-line tool. Opening pull requests, finding issues, checking CI results, publishing releases: the work you usually do in the browser, you can do right from your terminal. The first line of its help describes it like this. Commands follow the shape gh <command> <subcommand> [flags], naming the thing first and then the action, as in gh pr list.

Terminal

$ gh --help Work seamlessly with GitHub from the command line. USAGE gh <command> <subcommand> [flags] CORE COMMANDS auth: Authenticate gh and git with GitHub browse: Open repositories, issues, pull requests, and more in the browser codespace: Connect to and manage codespaces discussion: Work with GitHub Discussions (preview) gist: Manage gists issue: Manage issues org: Manage organizations pr: Manage pull requests project: Work with GitHub Projects. release: Manage releases repo: Manage repositories skill: Install and manage agent skills (preview) GITHUB ACTIONS COMMANDS cache: Manage GitHub Actions caches run: View details about workflow runs workflow: View details about GitHub Actions workflows

How it differs from git

The names look alike, but the jobs are clearly split. git works on your local repository: it makes commits and pushes to and pulls from a remote. Pull requests, issues, and Actions, on the other hand, are not part of git; they belong to the GitHub service. gh handles them by calling the GitHub API. So gh doesn't replace git; you use the two side by side.

Terminal

# git: work on your local repository and talk to the remote $ git switch -c fix-typo $ git commit -am "Fix a typo in the README" $ git push -u origin fix-typo # gh: call the GitHub API to open a PR, watch its checks, and merge it $ gh pr create --fill $ gh pr checks $ gh pr merge --squash --delete-branch

What gh can do

The help groups commands into CORE COMMANDS (repo, issue, pr, release, and more), GITHUB ACTIONS COMMANDS (run, workflow, cache), and ADDITIONAL COMMANDS (api, search, alias, extension, and more). Here are the main ones this course uses and the lessons where they appear. -R cli/cli means "work on the cli/cli repository"; Lesson 4 covers it in detail.

Terminal

$ gh repo view cli/cli # repositories (Lesson 4) $ gh issue list -R cli/cli # issues (Lesson 5) $ gh pr list -R cli/cli # pull requests (Lessons 6-7) $ gh run list -R cli/cli # Actions runs (Lessons 9-10) $ gh release list -R cli/cli # releases (Lesson 11) $ gh search repos --topic gh-extension # search (Lesson 15) $ gh api repos/cli/cli # the raw REST API (Lesson 17)

Getting results as JSON

Many gh commands return JSON instead of a table when you pass field names to --json. Below is real output from gh repo view cli/cli --json for cli/cli, the public repository where gh itself lives, trimmed to a few fields and embedded in the code. Let's read it with Python in your browser and pull out the key points.

editor.py

Tab indents. To leave the editor, press Esc, then Tab.

Create a free account to keep reading

With an account you can read the rest of this lesson, take the quiz, and read every free lesson in this course. Lessons you answer correctly are recorded as complete.

Report a problem with this lesson

Log in to send a report.

Keyboard shortcuts

Keys available in a lesson
KeyAction
[ or Alt + ←Go to the previous lesson
] or Alt + →Go to the next lesson
?Open this list
EscClose this list

The keys do not work while the cursor is in a code editor or an input field.