GitHub CLI and Developer Tools
6 learning objectives · 9 key terms · 11 commands · 2 diagrams · 5 quiz questions
GitHub CLI and Developer Tools
Automation & SecurityWhat you'll be able to do
- Install and authenticate the GitHub CLI
- Create and clone repositories without leaving the terminal
- File issues and open pull requests from the command line
- Inspect workflow runs and logs, and re-run failures
- Manage releases and query the API with gh api
- Define aliases for the commands you type most
The idea, in plain language
The GitHub CLI is a single binary, gh, that wraps the GitHub API in commands shaped like the rest of your terminal workflow. It matters because it removes context switches: you are already in the repository you are thinking about, you already know the branch name, and you already have the issue number in your scrollback. Creating the branch, the commit, the push and the pull request becomes one continuous session instead of a hop into a browser.
Authentication is the one-time setup and it is handled well: gh auth login supports a browser flow or a pasted token, writes to your system credential store, and tells git how to use it for HTTPS operations — so it can also solve the "why does git push keep asking for my password?" problem permanently. Read the scopes it requests; request only what you need.
Most gh commands mirror something you would otherwise do in the web interface, and everything is scriptable. gh pr create takes its title and body from flags or an editor and prints the URL, which means a shell function can open a perfectly formatted pull request every time. gh run watch follows a workflow run live, gh run view --log-failed shows only the failing step's output, gh api reaches anything not yet wrapped in a command, and gh alias set lets you name the five things you type a hundred times a day.
Key terms
- gh
- The GitHub CLI binary; run gh --version to confirm it is installed.
- gh auth login
- Interactive authentication; stores credentials and configures git to use them over HTTPS.
- gh repo create
- Creates a repository on GitHub, optionally from an existing local directory.
- gh pr create
- Opens a pull request from the current branch with title, body, base and reviewers.
- gh pr checkout
- Checks out someone else’s pull request locally by number — the fastest way to test a contribution.
- gh run list / watch
- Lists workflow runs and follows a run live in the terminal.
- gh api
- Direct access to any REST endpoint with automatic authentication and jq-style filtering.
- gh alias
- A saved shortcut for a gh command with your own arguments.
- gh extension
- Community-installed subcommands that add new gh capabilities.
How it works, step by step
- 1Install the CLI
Use your platform package manager so upgrades are one command. On Windows, winget; on macOS, Homebrew; on Linux, your distribution’s repository or the official apt repository.
installbash# macOS brew install gh # Windows winget install --id GitHub.cli # Ubuntu / Debian sudo apt install gh
- 2Authenticate once
The browser flow is easiest; the token flow suits headless machines. Use --scopes to request only what you need, and reply yes when it offers to configure git to use your GitHub credentials for HTTPS.
authenticatebashgh auth login --web --scopes "repo,read:org"
- 3Create or clone from the terminal
Create a new repository, or turn a local directory into one and push it without visiting the browser. Cloning by owner/name is shorter than remembering a full URL.
repositoriesbashgh repo create recipe-book --public --source=. --remote=origin --push gh repo clone ada/recipe-book
- 4Work with issues and pull requests
Create issues, list them, and open a pull request whose body comes from a template. Review someone else’s pull request by checking it out locally.
issues and PRsbashgh issue create --title "Session times out after 5 minutes" --label bug gh pr create --base main --title "Extend session timeout" --body "Closes #128" gh pr list --state open gh pr checkout 231
- 5Watch your automation from the terminal
List recent runs, follow one live, and read only the failing step’s log when something breaks — worth more than scrolling the web UI.
workflow runsbashgh run list --limit 5 gh run watch gh run view --log-failed
- 6Releases and raw API access
Create releases from tags with generated notes, then use gh api for anything without a dedicated command — filtering the JSON with --jq.
releases and APIbashgh release create v2.5.0 --generate-notes gh api repos/:owner/:repo --jq '.stargazers_count'
- 7Save the commands you type most as aliases
Aliases turn personal workflows into one-word commands. Shell aliases are not stored in the repository; gh aliases are, in your gh config, and they work from anywhere.
aliasesbashgh alias set co 'pr checkout' gh alias set mine 'pr list --author @me' gh co 231
Commands worth memorising
Every block below is copy-ready — use the Copy button, then paste it into your terminal. Expected output is shown underneath so you know what “working” looks like.
gh --versiongh version 2.62.0 (2026-02-11) https://github.com/cli/cli/releases/latest
If this fails, install updates have not reached your PATH — open a new terminal.
gh auth login --web✓ Authentication complete. ✓ Configured git protocol git@github.com. ✓ Logged in as ada
It also offers to configure git credentials, which fixes repeated HTTPS password prompts.
gh auth status
github.com ✓ Logged in to github.com account ada (keyring) - Active account: true - Token scopes: 'gist', 'read:org', 'repo'
The scopes line is the fastest way to diagnose permission errors.
gh repo create recipe-book --public --source=. --remote=origin --push
✓ Created repository ada/recipe-book on GitHub ✓ Added remote origin ✓ Pushed commits to https://github.com/ada/recipe-book.git
One command replaces creating on GitHub, adding a remote and pushing.
gh pr create --base main --title "Extend session timeout" --body "Closes #128"
https://github.com/ada/app/pull/231
Prints the URL, so your shell can open it or your script can capture it.
gh pr checkout 231branch 'fix/session-timeout' set up to track 'origin/fix/session-timeout'.
Checks the pull request out under its own branch name, so you can run and test it locally before approving.
gh run watch
✓ main Run Tests · 25183446201 ✓ Set up job ✓ Checkout repository ✓ Run tests
Follows the most recent run for the current branch and exits with a non-zero status on failure — useful in scripts.
gh run view --log-failed
Prints the log of the failing step only. Much faster than paging through a full run log.
gh release create v2.5.0 --generate-notes
https://github.com/ada/app/releases/tag/v2.5.0
Creates the release from the existing tag and fills the notes from merged pull requests.
gh api repos/:owner/:repo/branches/main/protection --jq '.required_pull_request_reviews.required_approving_review_count'
1
:owner and :repo are filled from the current repository, and --jq filters the JSON so scripts stay readable.
gh alias set mine 'pr list --author @me --state open'
Adding alias for mine
Aliases live in your gh config, so they follow you to any machine where you are authenticated.
Workflow diagrams
| Task | Web interface | CLI |
|---|---|---|
| Create a repository | New repository form | gh repo create |
| Open a pull request | Compare & pull request | gh pr create |
| Review a contribution locally | Download the branch | gh pr checkout 231 |
| File a bug | Issues → New issue | gh issue create |
| Watch CI | Actions tab, refresh | gh run watch |
| See why CI failed | Expand the failing step | gh run view --log-failed |
| Cut a release | Releases → Draft a new release | gh release create |
| Anything else | Whatever the UI exposes | gh api <endpoint> |
Same operations, same permissions, one context — the terminal you are already in.
- Anything the web interface can do, the CLI can do with the same account and permissions.
- The advantage is context: branch names, issue numbers and logs are already on screen.
- gh api covers features that have no dedicated command yet.
Two commands create the work item and the review; everything between is ordinary Git.
- The CLI files the issue with labels and assignees in one quoted command.
- Branching, committing and pushing stay in Git — the CLI adds no new concepts there.
- gh pr create opens the pull request and prints its URL.
- gh pr checks reports the status of required checks, which makes it scriptable as a gate.
Worked example
A complete change managed from the terminal, including watching the checks and merging.
gh auth status # ✓ Logged in to github.com account ada (keyring) gh issue create --title "Session times out after 5 minutes" \ --body "Expected 30 minutes idle; logged out after ~5." \\ --label bug --assignee @me --milestone v2.5 # https://github.com/ada/app/issues/128 git switch -c fix/session-timeout # ... edit auth/session.py ... git commit -am "Extend idle session timeout to 30 minutes (refs #128)" git push -u origin fix/session-timeout gh pr create --base main \ --title "Extend session idle timeout to 30 minutes" \ --body "Closes #128. Verified manually with a 31-minute idle test." gh pr checks --watch # ✓ test 1m12s # ✓ lint 22s gh pr merge --squash --delete-branch # ✓ Squashed and merged pull request #231 # ✓ Deleted branch fix/session-timeout git switch main && git pull gh issue view 128 --json state --jq .state # CLOSED
Issue filed, branch pushed, pull request reviewed by CI, squash-merged, branch deleted, issue closed — all without opening a browser.
Where you'll use it
Common mistakes
- Using a token with more scopes than needed because the default was accepted without reading.
- Assuming gh replaces Git — it wraps GitHub; commits and branches are still Git.
- Checking out pull requests for untrusted forks and running their code without reading it first.
- Letting gh create repositories with unexpected visibility because the default was not specified.
- Building fragile shell pipelines around gh api without --jq, then parsing JSON with grep.
- Storing long-lived tokens in shell profiles when gh auth login already manages them securely.
Best practices
- Authenticate with gh auth login and let it configure git credential handling for HTTPS.
- Request the minimum scopes and re-authenticate when you need more.
- Use gh pr create with a template or heredoc so descriptions stay consistent.
- Watch runs with gh run watch and read failures with gh run view --log-failed.
- Save your five most-typed commands as gh aliases.
- Use gh api for anything the CLI does not wrap, with --jq for readable output.
- Treat gh output as an interface: it prints URLs and exits with meaningful status codes, so it composes with scripts.
Hands-on exercise
Do a whole change without a browser
File, fix, review and merge from one terminal session.
- Run gh --version and gh auth status, and note the token scopes reported.
- In a practice repository, file an issue with gh issue create including a label and an assignee.
- Create a branch, make the change, commit, and push. Then open the pull request with gh pr create, linking the issue with a closing keyword.
- Run gh pr checks --watch and read the result. If checks fail, use gh run view --log-failed to find the cause.
- Merge with gh pr merge --squash --delete-branch and confirm the issue closed with gh issue view <number> --json state.
- Create an alias for the command you found yourself typing most in this exercise, and use it once.
💡 Hint: gh commands infer the repository from the current directory’s git remote, so run them from inside the clone — or pass --repo owner/name explicitly.
Done when: You filed an issue, opened and merged a pull request, and closed the issue, all without opening the GitHub website.
Checkpoint quiz
0 of 5 answered · 0 correct
- Multiple choiceQ1
What does gh auth login configure besides the CLI itself?
- Command outputQ2
What does this command print for the current repository?
gh api repos/:owner/:repo --jq '.stargazers_count'
- TroubleshootingQ3
You need to verify a contributor’s pull request locally before approving it. Which command?
- True or falseQ4
True or false: the GitHub CLI can be used inside GitHub Actions workflows, so a workflow can create releases without extra setup.
- Multiple choiceQ5
Which gh command shows only the failing step’s output of a workflow run?
Module summary
- gh wraps the GitHub API in terminal-native commands with the same account and permissions as the web interface.
- gh auth login handles credentials and can configure git for HTTPS, removing repeated password prompts.
- gh repo create, gh pr create, gh issue create and gh release create cover the everyday operations.
- gh pr checkout <number> is the fastest way to test a contribution locally.
- gh run list, gh run watch and gh run view --log-failed make CI observable from the terminal.
- gh api reaches anything unwrapped, and --jq keeps script output readable.
- Aliases turn your most-typed commands into one word.
Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Put the GitHub course to work: open one of the company-wise repositories and follow the workflow you just learned, branch to release.