Home Coding & Scripting Getting Started with the GitHub CLI (gh)

Getting Started with the GitHub CLI (gh)

267
0

The GitHub CLI is a command-line tool that helps you interact with GitHub directly from your terminal. Instead of switching between your browser and your code editor, you can perform many GitHub tasks—like creating repositories, managing pull requests, and reviewing issues—without leaving your command line.

This post will help you understand what the GitHub CLI is, how to set it up, and how to start using it with simple and clear steps.


1. What Is GitHub CLI?

The GitHub CLI (command: gh) brings GitHub workflows into your terminal. You can:

  • Create and view repositories
  • Clone projects
  • Manage issues and pull requests
  • Work with GitHub Actions
  • Automate tasks using aliases and scripts
  • Extend features using CLI extensions

If you already use Git and the terminal for development, the GitHub CLI becomes a natural extension of your workflow.


2. Getting Started Before You Try Any Commands

Before running your first command, make sure the GitHub CLI is installed and authenticated on your system.

Step 1: Install the GitHub CLI

You can install it using package managers or installers depending on your operating system.

Step 2: Verify installation

After installation, check whether the CLI is working:

gh --version

Step 3: Log in to GitHub

Next, authenticate the CLI with your GitHub account:

gh auth login

You’ll be guided through a simple login process using your browser or a token. After successful login, all GitHub-related commands will work smoothly.

Step 4: Check authentication

gh auth status

Once you complete these steps, you’re ready to try out the commands in the next sections.


3. Core Commands to Start With

Now that the CLI is installed and authenticated, here are some of the most commonly used commands you can try.

Working with Repositories

  • Create a new repository
gh repo create
  • Clone a repository
gh repo clone owner/repo
  • View repository details
gh repo view

Add --web to open the repo in the browser.


Working with Issues

  • List issues
gh issue list
  • Create a new issue
gh issue create
  • View a specific issue
gh issue view ISSUE_NUMBER

Working with Pull Requests

  • List pull requests
gh pr list
  • Create a new pull request
gh pr create
  • Merge a pull request
gh pr merge NUMBER

You can choose merge, squash, or rebase styles.


Working with GitHub Actions

  • List workflow runs
gh run list
  • View details of a run
gh run view RUN_ID
  • Rerun a workflow
gh run rerun RUN_ID

4. Productivity Features

Aliases

If you run a command frequently, you can create shortcuts:

gh alias set myprs "pr list --author @me"

Now, running:

gh myprs

will show all PRs created by you.


JSON Output for Scripting

Many commands support JSON output so you can use them in automation:

gh pr list --json number,title

This makes GitHub CLI useful for scripts, CI/CD, and workflow automation.


Extensions

You can install custom extensions to add new commands:

gh extension install owner/extension-name

Or browse available ones:

gh extension browse

5. Tips for a Better Workflow

  • Run gh help or gh help <command> to explore options
  • Use aliases to simplify long or frequently used commands
  • Stay in your repository folder before running most commands for automatic context
  • Automate repetitive tasks using scripts
  • Combine the CLI with Git for a complete terminal-based workflow

6. Summary

The GitHub CLI is a powerful tool that simplifies your development workflow by bringing GitHub operations into the command line. Once installed and authenticated, you can manage repositories, issues, pull requests, workflows, and automation all from your terminal. It’s simple, efficient, and especially useful for developers who prefer to stay in their coding environment.


References

(Full URLs, as requested)

Previous articleGetting Started with SourceTree for a Visual Git Workflow
Next articleWhat Is Git Credential Manager and Why It Matters
Heartin Kanikathottu
As a seasoned Cloud and Security Architect, I’ve led transformative initiatives in key roles, including Vice President at Morgan Stanley, Principal Architect at Societe Generale, and Tech Lead & Cloud Security Architect at VMware, among others. I’m also an internationally published author with multiple books available on platforms like Amazon and O'Reilly. Notably, one of my books was recognized as the 8th best cloud computing book of all time in 2020, reflecting the impact of my contributions to the field. With over 15 professional certifications from providers such as Microsoft (Azure), Amazon (AWS), Oracle (Java), Pivotal (Spring), and IBM, I bring a wealth of expertise to my work. Academically, I hold dual Master’s degrees in Cloud Computing and Data Analytics. I’m passionate about sharing knowledge and mentoring others, which is why I actively speak at global technical forums such as Tech Opportunities Fest at Platform Calgary, Google's Kubernetes Meetup, Java User Group, Elasticsearch Meetup, and the Agile India Conference.

LEAVE A REPLY

Please enter your comment!
Please enter your name here