GitHub CLI (gh): The ‘Secret Weapon’ for Managing PRs and Issues Directly in the Terminal

Git tutorial - IT technology blog
Git tutorial - IT technology blog

A Familiar Scene: When the Terminal and Browser Are Out of Sync

As a developer, you’re likely all too familiar with this routine: you finish typing git push, then hit Alt + Tab to switch to Chrome. Next, you press F5, wait for the repo to load, and finally click the “Compare & pull request” button. Lastly, you type out the title and description in the web interface.

It sounds simple enough. However, when a project hits its peak and you’re dealing with dozens of PRs a day, jumping back and forth between the browser and the Terminal becomes incredibly frustrating. Every time you context switch, it takes your brain about 60-90 seconds to regain focus. Plus, those open YouTube or Facebook tabs are just waiting to distract you.

I once accidentally merged an untested branch simply because I had too many identical-looking tabs open. After that painful mistake, I decided to lock the main branch and bring the entire GitHub workflow back to where it belongs: the Terminal.

Why the Web Interface Can Sometimes Be a Burden

Git is great at managing code, but GitHub is a complex collaboration platform with Issues, PRs, and Actions. While GitHub’s web interface is sleek, it still has inherent drawbacks:

  • Too many clicks: Finding a specific old Issue can sometimes require clicking through 3 or 4 layers of menus.
  • Annoying latency: For large repos with thousands of comments, the browser often stutters or loads very slowly.
  • Hard to automate: You can’t write a script to “click” your way through creating bulk PRs for 10 microservices at once.

Legacy Solutions and Their Limitations

Before GitHub CLI (gh) was born, developers often used several workarounds:

  1. Git Alias/Curl: Writing custom scripts to call the GitHub API. This is extremely hard to maintain and risks exposing security tokens.
  2. Hub: The predecessor to gh. GitHub has since deprioritized Hub to focus on its newer tool.
  3. GUI Tools (GitKraken, Sourcetree): Visually appealing but RAM-heavy. Most importantly, they still force you to leave the command line you were just working on.

Mastering GitHub CLI (gh): A Tool for Pro Developers

GitHub CLI is more than just a supporting tool; it’s a true “virtual assistant” right in your Terminal, much like a terminal UI for visual management. Here is how I save at least 30 minutes every day using gh.

1. Installation and Authentication in a Snap

Installing gh is easy via Homebrew (macOS) or Scoop (Windows). Once installed, run the following command:

gh auth login

Choose browser-based authentication. You only need to do this once. gh will automatically handle the rest for all future repositories.

2. Managing Issues: Never Take Your Eyes Off the Code

Instead of fumbling for the Issues tab, try these commands:

# List issues assigned to me
gh issue list --assignee "@me"

# View issue 42 content directly in the terminal
gh issue view 42

# Quickly create a new issue with a label
gh issue create --title "CSS display issue on Mobile" --body "Button padding overflow" --label "bug"

Every action happens in an instant, keeping your train of thought uninterrupted.

3. Pull Requests – The ‘Worth Its Weight in Gold’ Feature

This is where gh truly shines. To create a PR from the current branch, I just type:

gh pr create --fill

The --fill parameter automatically uses the commit title as the PR title. If you want a final visual check, add the --web flag to automatically open that specific PR page in your browser.

Reviewing code for colleagues also becomes much easier:

# Quickly checkout PR 105's branch to test locally
gh pr checkout 105

# Merge the PR and automatically delete the stale branch
gh pr merge --merge --delete-branch

Using gh pr merge is safer than standard Git commands because it includes checks for CI/CD status before merging.

4. Professional Releases for DevOps

Don’t let creating a Release become a nightmare at the end of every sprint. With gh, you can attach build files and generate a changelog in a single command:

gh release create v1.1.0 ./dist/app.zip --generate-notes

The --generate-notes flag automatically aggregates all merged PR titles to create a highly professional Release Note.

Quick Tips for a Smoother Workflow

Take advantage of Aliases to make gh your own. For example, I often alias the PR status command to something short:

gh alias set ps 'pr status'

If you prefer a “hacker” style, combine it with fzf (a fuzzy finder). The command below allows you to quickly select a PR from a list to checkout without needing to remember the ID:

gh pr list | fzf | awk '{print $1}' | xargs gh pr checkout

Conclusion: Is It Worth the Switch?

Using GitHub CLI isn’t about showing off command-line skills. The ultimate goal is to protect your focus. Saving a few seconds of clicking might seem minor, but added up, it helps you maintain a state of Deep Work more effectively.

Try installing gh and use it consistently for a week. I bet you’ll soon find yourself wondering: “Why did I stick with the web version for so long?”

Share: