Introduction
Most developers interact with GitHub through a web browser. We open GitHub, create repositories, review pull requests, manage issues, and create releases through the website.
But what if you could perform all those actions directly from your terminal?
That is exactly what GitHub CLI, commonly known as gh, allows you to do.
GitHub CLI is an official command-line tool developed by GitHub that enables developers to work with GitHub without constantly switching between their code editor, terminal, and browser.
By the end of this guide, you will understand:
- What GitHub CLI is
- Why it exists
- How to install it
- How authentication works
- Common commands every developer should know
- Real-world workflows
- Best practices and tips
What is GitHub CLI?
GitHub CLI is a command-line application that lets you interact with GitHub from your terminal.
Instead of visiting:
https://github.com
and clicking through menus, you can perform GitHub operations using commands.
For example:
gh repo create
creates a repository.
gh pr create
creates a pull request.
gh issue create
creates an issue.
gh release create
creates a release.
Why Was GitHub CLI Created?
Before GitHub CLI existed, developers typically had three options:
Option 1: Use the GitHub Website
Pros:
- Easy to understand
- Visual interface
Cons:
- Constant context switching
- Slower for repetitive tasks
Option 2: Use Git Commands
Git commands help manage source control:
git commit
git push
git pull
git branch
However, Git itself does not manage:
- Pull Requests
- Issues
- Releases
- Discussions
These are GitHub features.
Option 3: Use GitHub APIs
GitHub provides APIs.
Example:
curl \
-H "Authorization: Bearer TOKEN" \
https://api.github.com/repos/user/project/issues
This works but can become complex.
GitHub CLI bridges this gap.
It provides a simple developer-friendly interface over GitHub APIs.
Git vs GitHub CLI
Many beginners confuse Git and GitHub CLI.
| Git | GitHub CLI |
|---|---|
| Version control system | GitHub management tool |
| Works locally | Communicates with GitHub |
git push |
gh pr create |
git branch |
gh issue create |
git merge |
gh release create |
Think of it like this:
Git = Manage code history
GitHub CLI = Manage GitHub platform features
Installing GitHub CLI
Ubuntu
sudo apt update
sudo apt install gh
Verify:
gh --version
Example output:
gh version 2.70.0
macOS
Using Homebrew:
brew install gh
Windows
Using Winget:
winget install GitHub.cli
First-Time Authentication
After installation:
gh auth login
You will see options such as:
? What account do you want to log into?
GitHub.com
Choose:
GitHub.com
Then:
HTTPS
Then:
Login with browser
GitHub CLI will generate a code.
Example:
First copy your one-time code:
ABCD-EFGH
Open the browser and authenticate.
Check Authentication Status
gh auth status
Example:
Logged in to github.com
Creating a Repository
Create a repository directly from the terminal.
gh repo create my-project
Interactive mode will ask:
Public or Private?
Choose your preference.
Cloning a Repository
Traditional Git:
git clone https://github.com/user/project.git
GitHub CLI:
gh repo clone user/project
Example:
gh repo clone octocat/demo
Viewing Repository Information
gh repo view
Example output:
Repository:
user/project
Description:
My project
Stars:
120
Creating Issues
Issues are used to track bugs and feature requests.
Create one:
gh issue create
Interactive prompts appear.
You can also provide everything directly:
gh issue create \
--title "Login Bug" \
--body "Users cannot log in"
Listing Issues
gh issue list
Example:
#23 Login Bug
#24 Add Dark Mode
#25 Improve Performance
Viewing a Specific Issue
gh issue view 23
Creating Pull Requests
One of the most powerful features.
After pushing a branch:
git push origin feature/login
Create a PR:
gh pr create
GitHub CLI asks:
Title?
Description?
Base branch?
Then creates the pull request.
Listing Pull Requests
gh pr list
Example:
#45 Add Login Feature
#46 Fix Database Error
Viewing Pull Requests
gh pr view 45
Checking Out a Pull Request
Instead of manually fetching branches:
gh pr checkout 45
This automatically switches to the PR branch.
Reviewing Pull Requests
Approve:
gh pr review 45 --approve
Request changes:
gh pr review 45 --request-changes
Comment:
gh pr review 45 --comment
Merging Pull Requests
gh pr merge 45
Options:
gh pr merge 45 --merge
gh pr merge 45 --squash
gh pr merge 45 --rebase
Working with Releases
A release is a published version of software.
Example:
v1.0.0
v1.1.0
v2.0.0
Create a Release
gh release create v1.0.0
Add Release Notes
gh release create v1.0.0 \
--notes "Initial release"
Upload Files
gh release create v1.0.0 \
dist/app.tar.gz
This is likely what happened in your project.
Your Makefile probably executes something similar to:
gh release create \
v1.0.0 \
dist/registry-data-v1.0.0.tar.gz
Without GitHub CLI installed, that step fails.
Viewing Releases
gh release list
Example:
v1.0.0
v1.1.0
v2.0.0
Download Release Assets
gh release download v1.0.0
Working with GitHub Actions
View workflows:
gh workflow list
View workflow runs:
gh run list
Inspect a run:
gh run view
Watch live logs:
gh run watch
Working with Gists
Create a gist:
gh gist create notes.txt
List gists:
gh gist list
Useful Commands Every Developer Should Know
Authentication
gh auth login
gh auth status
gh auth logout
Repositories
gh repo create
gh repo clone
gh repo view
Issues
gh issue create
gh issue list
gh issue view
Pull Requests
gh pr create
gh pr list
gh pr view
gh pr checkout
gh pr merge
Releases
gh release create
gh release list
gh release view
Real-World Example Workflow
Imagine you are implementing a feature.
Step 1
Create a branch:
git checkout -b feature/payment
Step 2
Write code.
Step 3
Commit changes:
git add .
git commit -m "Add payment support"
Step 4
Push:
git push origin feature/payment
Step 5
Create PR:
gh pr create
Step 6
Review PR:
gh pr view
Step 7
Merge:
gh pr merge
Step 8
Create Release:
gh release create v1.0.0
Entire workflow completed without opening GitHub in a browser.
Advantages of GitHub CLI
Faster Workflow
No browser switching.
Automation Friendly
Perfect for scripts and CI/CD pipelines.
Consistent Interface
Everything from one terminal.
Developer Productivity
Reduces repetitive work.
Official Tool
Maintained by GitHub.
When Should You Use GitHub CLI?
Use GitHub CLI if you:
- Work with GitHub daily
- Create pull requests frequently
- Manage releases
- Handle issues regularly
- Build automation scripts
- Work in DevOps or platform engineering
Common Beginner Mistakes
Forgetting Authentication
gh auth login
must be completed first.
Confusing Git with GitHub CLI
Remember:
Git manages code history.
GitHub CLI manages GitHub features.
Missing Permissions
Your GitHub account must have permissions for the repository.
Not Updating GitHub CLI
Keep it updated:
sudo apt update
sudo apt upgrade gh
Summary
GitHub CLI (gh) is GitHub's official command-line tool that allows developers to manage repositories, issues, pull requests, releases, workflows, and many other GitHub features directly from the terminal.
For a junior developer, learning GitHub CLI provides several benefits:
- Faster development workflows
- Less dependence on the browser
- Easier automation
- Better understanding of GitHub operations
- Improved productivity in professional software teams
If you're already comfortable with commands like:
git add
git commit
git push
then learning:
gh pr create
gh issue create
gh release create
is the next natural step toward becoming a more efficient developer.
Top comments (0)