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 helporgh 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)
- https://docs.github.com/get-started/using-github/github-cli
- https://docs.github.com/en/github-cli
- https://cli.github.com/manual/
- https://www.codecademy.com/article/github-cli-tutorial
- https://www.freecodecamp.org/news/how-to-use-github-from-the-command-line/
- https://github.blog/developer-skills/github/how-to-level-up-your-git-game-with-github-cli