GitHub CLI: The Secret Weapon You're Not Using โก๐
GitHub CLI: The Secret Weapon You're Not Using โก๐
Real talk: If you're still clicking through GitHub's web interface to create PRs, you're living in the Stone Age. ๐ฆ
I used to be you. Click, click, scroll, paste, type, click again. Then I discovered gh - GitHub's official CLI tool - and suddenly I'm creating pull requests in 3 seconds without leaving my terminal.
It's not just faster. It's a whole different way of working. Let me show you why you need this in your life!
What Even Is GitHub CLI? ๐ค
Think of it as GitHub's web interface, but on steroids and living in your terminal.
The magic:
- Create PRs without touching your mouse
- Review code from the command line
- Manage issues like a boss
- Run workflows with one command
- Clone repos faster than you can say "git clone"
Translation: Everything you do on github.com, but 10x faster and infinitely cooler! ๐
Why You Should Care ๐ก
Before GitHub CLI:
# The old way (7 steps!)
git add .
git commit -m "Fix bug"
git push origin feature-branch
# Open browser
# Navigate to GitHub
# Click "Compare & pull request"
# Fill out the form
# Click "Create pull request"
After GitHub CLI:
# The new way (2 commands!)
git add . && git commit -m "Fix bug" && git push
gh pr create --fill
# Done! PR created! โจ
Time saved: About 30 seconds per PR. Do this 20 times a day? That's 10 minutes saved daily. Over a year? 60+ hours of your life back!
Plus, you look like a hacker from a movie. Your non-technical friends will be impressed! ๐ฌ
Getting Started (It Takes 2 Minutes) โ๏ธ
Installation
macOS:
brew install gh
Linux:
# Ubuntu/Debian
sudo apt install gh
# Fedora/RHEL
sudo dnf install gh
Windows:
# Using winget
winget install --id GitHub.cli
# Or use Chocolatey
choco install gh
The Magic Login
# Authenticate with GitHub
gh auth login
# Follow the prompts:
# 1. Choose GitHub.com (unless you use Enterprise)
# 2. Choose HTTPS or SSH (I use HTTPS)
# 3. Authenticate in browser
# That's it! You're a CLI wizard now! ๐งโโ๏ธ
Pro tip: The authentication works for both gh and regular git commands. One login, infinite power!
The Commands That'll Change Your Life ๐ฏ
1. Creating PRs (The Game-Changer)
The lazy way (auto-fill everything):
gh pr create --fill
What it does:
- Creates PR from your current branch
- Uses your commit messages as PR description
- Opens in your default branch
- Time saved: 30 seconds per PR!
The detailed way:
gh pr create --title "Add user authentication" \
--body "Implements JWT auth with refresh tokens" \
--reviewer alice,bob \
--label "enhancement" \
--assignee @me
The interactive way (my favorite!):
gh pr create
# It'll ask you:
# - Title? (suggests from commits)
# - Description? (pulls from commits)
# - Which branch? (knows your default)
# - Submit? (y/n)
Real story: I used to spend 2 minutes per PR filling out forms. Now it's literally 5 seconds. My productivity went ๐!
2. Checking Out PRs (Code Review on Steroids)
Someone sent you a PR? Check it out instantly:
# See all PRs
gh pr list
# Check out PR #42 to review it locally
gh pr checkout 42
# Now you can run it, test it, break it!
The power move:
# Review PR #42 with comments
gh pr review 42
# Approve it
gh pr review 42 --approve
# Request changes with a comment
gh pr review 42 --request-changes \
--body "Looks good but needs tests!"
Why this is awesome: Test PRs locally BEFORE merging. No more "it worked on their machine" surprises! ๐
3. Managing Issues (Like a Boss)
Create an issue (from your terminal!):
gh issue create --title "Button doesn't work on mobile" \
--body "Tested on iPhone 13, button is invisible" \
--label "bug"
List issues:
# All issues
gh issue list
# Only YOUR issues
gh issue list --assignee @me
# Only bugs
gh issue list --label bug
# Open issues in browser
gh issue list --web
Close an issue:
gh issue close 123
The workflow:
# Morning standup routine
gh issue list --assignee @me
# See what you're working on
# Pick one, get to work
# Close it when done
# Repeat!
No more context switching to your browser! Stay in the zone! ๐ฎ
4. Repo Operations (Speed Run Edition)
Clone repos faster:
# Old way
git clone https://github.com/facebook/react.git
# New way (shorter!)
gh repo clone facebook/react
# Even works with short syntax
gh repo clone react
# If you're in facebook's org!
Create a new repo:
# Create locally and on GitHub at the same time!
gh repo create my-awesome-project --public --source=. --remote=origin
# Translation:
# - Creates GitHub repo
# - Initializes local repo
# - Sets up remote
# - All in ONE command!
Fork repos:
# Fork and clone in one shot
gh repo fork vercel/next.js --clone
# Start contributing immediately!
The magic: No more clicking through GitHub's "New Repository" form! ๐
5. GitHub Actions (CI/CD from Your Terminal)
Watch your workflow runs:
# See all workflow runs
gh run list
# Watch a specific run (LIVE!)
gh run watch
# See logs from the latest run
gh run view --log
Re-run failed workflows:
# Retry the latest failed run
gh run rerun
# Retry a specific run
gh run rerun 123456789
Real use case:
# Push code
git push
# Immediately watch the CI run
gh run watch
# See it pass in real-time
# Or catch failures FAST!
Why I love this: No more refreshing the Actions tab! Live updates in your terminal! ๐ฅ
The Power User Moves ๐ช
Aliases (Make It Your Own)
# Create shortcuts for common commands
gh alias set prc 'pr create --fill'
gh alias set prv 'pr view --web'
gh alias set issues 'issue list --assignee @me'
# Now use them
gh prc # Create PR instantly
gh prv # View current PR in browser
gh issues # See your issues
My personal favorites:
# Quick PR
gh alias set quickpr '!git push && gh pr create --fill'
# Today's work
gh alias set today 'issue list --assignee @me --label "in-progress"'
# Latest actions
gh alias set ci 'run watch'
Combined Workflows (The Real Magic)
The "Push and PR" one-liner:
git add . && git commit -m "Add feature" && git push && gh pr create --fill
The "Review and Approve" speedrun:
gh pr checkout 42 && npm test && gh pr review 42 --approve
The "Issue to Branch" workflow:
# Create a branch from an issue
gh issue develop 123 --checkout
# Work on it, push
git push
# Create PR that closes the issue
gh pr create --fill --body "Closes #123"
Mind = Blown! ๐คฏ
Cool Tricks You Didn't Know Existed ๐ช
1. Interactive Modes
# Browse issues interactively
gh issue list --web
# Browse PRs interactively
gh pr list --web
# Choose from a list with arrow keys!
2. Output as JSON (For Script Nerds)
# Get PR data as JSON
gh pr list --json number,title,author
# Pipe it to jq for processing
gh pr list --json title,number | jq '.[] | .title'
# Build custom dashboards!
3. GitHub Codespaces (From CLI!)
# Create a codespace
gh codespace create
# Connect to it
gh codespace ssh
# Code in the cloud from your terminal!
4. The Secret gh browse Command
# Open current repo in browser
gh browse
# Open specific PR
gh browse 42
# Open issues page
gh browse -- issues
# Open Actions page
gh browse -- actions
Use case: Terminal workflow, but need the browser for ONE thing? gh browse! ๐ฏ
The Cheat Sheet You'll Bookmark ๐
# PRs
gh pr create --fill # Create PR
gh pr list # List PRs
gh pr checkout 42 # Check out PR #42
gh pr review 42 --approve # Approve PR
gh pr merge 42 # Merge PR
gh pr view 42 # View PR details
# Issues
gh issue create # Create issue
gh issue list # List issues
gh issue close 123 # Close issue
gh issue view 123 # View issue
# Repos
gh repo clone user/repo # Clone repo
gh repo create my-repo # Create repo
gh repo fork user/repo # Fork repo
gh repo view # View current repo
# Actions
gh run list # List workflow runs
gh run watch # Watch live run
gh run view --log # View logs
# Auth
gh auth login # Login
gh auth status # Check status
# Help
gh help # General help
gh pr --help # PR-specific help
Print this, tape it to your monitor, become unstoppable! ๐ช
When GitHub CLI Really Shines โญ
Use Case 1: Rapid Development
# Your flow:
# 1. Fix bug
git commit -am "Fix login bug"
# 2. Push and create PR
git push && gh pr create --fill
# 3. Watch CI
gh run watch
# 4. Merge when green
gh pr merge --auto
Time per iteration: 10 seconds. You're a machine! ๐ค
Use Case 2: Code Reviews
# Morning review routine
gh pr list
# Pick one
gh pr checkout 42
# Test it locally
npm test
# Approve if good
gh pr review 42 --approve --body "LGTM! ๐"
# Next PR
gh pr checkout 43
Review 10 PRs before your coffee gets cold! โ
Use Case 3: Issue Triage
# See what's new
gh issue list --label "needs-triage"
# Quick fix? Create branch
gh issue develop 123 --checkout
# Not a bug? Close with comment
gh issue close 124 --comment "Working as designed"
# Needs more info? Label it
gh issue edit 125 --add-label "needs-info"
Triage 20 issues in 5 minutes! ๐โโ๏ธ
Common Pitfalls (Learn from My Mistakes) ๐จ
Mistake #1: Forgetting to Push
# This WON'T work
gh pr create --fill
# Error: no commits pushed yet!
# Remember to push first!
git push && gh pr create --fill
Lesson: PR creation needs your branch on GitHub!
Mistake #2: Wrong Directory
# Running gh commands outside a git repo
cd ~/Documents
gh pr create
# Error: not in a git repository
# Always run gh commands IN your project!
Mistake #3: Not Checking PR Status
# Creating PR when one already exists
gh pr create --fill
# Error: PR already exists!
# Check first
gh pr list
The Bottom Line ๐ฏ
GitHub CLI is like having a GitHub superpower. You're not just "using GitHub" anymore - you're dominating it!
What you learned today:
- Create PRs in 3 seconds (
gh pr create --fill) - Review PRs locally (
gh pr checkout) - Manage issues without the browser (
gh issue list) - Clone repos with less typing (
gh repo clone) - Watch CI/CD runs live (
gh run watch) - Build custom workflows with aliases
- Look incredibly cool doing it all ๐
The best part? This is just scratching the surface. GitHub CLI has SO many more features:
- Releases management
- Gists from terminal
- Secrets management
- API calls
- Extensions
Most importantly: You'll save hours every week and never break your terminal flow again!
Your Action Plan ๐
Today:
- Install GitHub CLI (
brew install ghor equivalent) - Run
gh auth login - Try
gh pr listin your current project
This Week:
- Create your next PR with
gh pr create --fill - Review a PR with
gh pr checkout - Set up 2-3 aliases for your common workflows
This Month:
- Never open GitHub in browser for basic tasks
- Share this with your team
- Become the CLI wizard everyone admires
- Enjoy your new superpower! ๐ฆธโโ๏ธ
Pro Tips from the Trenches ๐
Tip #1: Combine with fzf for fuzzy finding:
gh pr list | fzf
# Select PR with fuzzy search!
Tip #2: Use tab completion:
# Enable it (bash)
gh completion -s bash > /usr/local/etc/bash_completion.d/gh
# Now tab-complete everything
gh pr <TAB>
Tip #3: Set your editor for PR descriptions:
export EDITOR=vim
# Or code, nano, emacs, whatever you prefer
Tip #4: Check out GitHub CLI extensions:
gh extension list
gh extension install owner/repo
# Extend gh with community plugins!
The Truth About Productivity ๐
Before GitHub CLI:
- 5 browser tabs open for GitHub
- Constant context switching
- 2 minutes per PR
- 10 minutes of waiting for CI feedback
After GitHub CLI:
- Terminal stays focused
- No context switching
- 5 seconds per PR
- Real-time CI updates
The math: If you create 10 PRs a week, you save 20 minutes weekly = 17+ hours yearly!
That's time for learning, building, or just enjoying life! ๐
Resources You Need ๐
Official Docs:
- GitHub CLI: cli.github.com
- Manual: cli.github.com/manual
Learning:
gh --help(seriously, read it!)gh pr --help(detailed help per command)- GitHub CLI discussions (for advanced tricks)
Extensions:
Ready to level up? Connect with me on LinkedIn - Share your favorite gh tricks!
Want to see my CLIs in action? Check out my GitHub and follow this blog!
Now go install gh and never open GitHub in a browser again! โกโจ