GitHub CLI 1.0: All you need to know

Search for a command to run...

The series content will mostly cover Git and GitHub tutorials and my recent learnings and experience in Git.
Hello reader! Ever wanted to commit something to a git repo with a past date? Here’s how you could do it. If you are working on a project and missed a commit yesterday or you accomplished the task but GitHub for Windows bailed on you? Well, this lit...
All you need to know about Hacktoberfest 2021

Hello reader! Well, Hacktoberfest is something, you are gonna hear a lot about in the coming month. You can refer to my YouTube video Tutorial to see a working tutorial for better understanding and a step-by-step guide of the same. https://www.yo...

Hello reader! In this Blog post, I will share some useful code snippets and functions in Python. Give it a read. Let's get started! 1. Memory The method getsizeof can be used to retrieve the size of any object. Here's an example of the same. import...

Hello reader! Whenever a client sends a request to the server, the response always contains a status code. You might not see it always but it's returned at every client-server interaction. Well, even if you are not a programmer, you would still know...

Hello reader! Microsoft subsidiary GitHub launched Copilot to power pair programming with AI. In this blog post, I will share all you need to know about it. You can refer to my YouTube video Tutorial to see a working tutorial for better understandin...

Earlier this year, GitHub announced the beta of GitHub CLI and GitHub CLI 1.0 is now available.
GitHub CLI basically brings GitHub to your terminal. With GitHub CLI, developers can check the status of GitHub issues and pull requests, search for a specific issue or PR, create/fork a repo, or create new issues and pull requests right from the command line.
It reduces context switching, helps you focus, and enables you to more easily script and create your own workflows.
What will be covered in this blog post:
Let's start with a brief overview of GitHub CLI. GitHub CLI can be best described as “GitHub from the command line.”
With GitHub CLI 1.0, you can:
Run your entire GitHub workflow from the terminal, from issues through releases
Call the GitHub API to script nearly any action, and set a custom alias for any command
Connect to GitHub Enterprise Server in addition to GitHub.com
gh is GitHub on the command line. It brings pull requests, issues, and other GitHub concepts to the terminal next to where you are already working with git and your code.
To install GitHub CLI on your machine, you can refer to the installation guide found on GitHub. To download click the Link Click the link to navigate to the guide
GitHub CLI is available across all platforms, MacOS, Windows and various Linux.
After a successful installation, you need to authenticate your Github account.
To authenticate your account you need to use the following command.
gh auth login
Follow the series of steps to complete your authentication process. After authentication, you can use the GitHub CLI.
gh repo command is used to create, clone, fork, and view repositories.
Display the description and the README of a GitHub repository. With no argument, the repository for the current directory is displayed.
gh repo view [<repository>] [flags]
Open a repository in the browser
You can open the repository in a web browser with -w, --web commands instead.
To create a new GitHub repository use the following command.
gh repo create [<name>] [flags]
for example: create a repository with a specific name
$ gh repo create demo-repository
Lets fork of a repository with GitHub CLI.
If you don't provide any argument, creates a fork of the current repository. Otherwise, forks the specified repository.
gh repo fork [<repository>] [flags]
Let’s explore the use of GitHub CLI for managing pull requests.
gh pr list
If we want to list out ALL of the pull requests, both open and closed, we could use the “state” flag
gh pr list --state "all"
gh pr list -s "all"
when listing out all PRs, instead of using this full command
gh pr list --label "labelname"
If you wish to check the status the PRs you created earlier, you can use the status command to list them at the terminal
gh pr status
This will give you a list of PRs that are assigned to you, mentioning you, or that were opened by you.
If you wish to check whether a PR is closed or not, use the following command.
gh pr list --state "closed"
gh pr list -s "closed"
If you wish to list out all of our open bug fix PRs, you could check by listing all the open PRs again
You could also filter by the defining label-name in the GitHub repo.
You can open the PR from the command line using the view command.
gh pr view [<number> | <url> | <branch>] [flags]
It will open the pull request in a web browser where you can then assign it to yourself, review it, etc.
You can use the following command to create a new pull request directly from the command line.
gh pr create --title "Pull request title" --body "Pull request body"
You’ll have an option to submit the PR, you can open it the browser, or cancel.
If you prefer to create your PR from the web, you could use the following command to open up a browser window.
gh pr create --web
You can checkout a Pull Request in GitHub CLI using the following command.
gh pr checkout {<number> | <url> | <branch>} [flags]
gh issue list
If we want to list out ALL of the issues we could use the state flag
gh issue list --state "all"
gh issue list -s "all"
You can use the following command to list them at the terminal.
gh issue status
This will give you a list of issues that are assigned to you, mentioning you, or that were opened by you.
In case you cannot find the issue you’re looking for, so let's check if its closed.
gh issue list --state "closed"
gh issue list -s "closed"
If you wish to filter out you can filter by the “labelname” label defined in your GitHub repo
gh issue list --label "labelname"
gh issue list -l "labelname"
You can open the issue from the command line using the following command.
gh issue view {<number> | <url>} [flags]
for example:
gh issue view "10"
You can create an issue with the help of the following command.
gh issue create --title "Issue title" --body "Issue body"
At the end you’ll have an option to submit the issue, open it the browser, or cancel.
If you still prefer to create your issue from the web, you could use the following command
gh issue create --web
You can list your gists with GitHub CLI using the following command.
gh gist list [flags]
You can view your gists with GitHub CLI using the following command.
gh gist view {<gist id> | <gist url>} [flags]
Create a new GitHub gist with given contents. Gists can be created from one or multiple files. Alternatively, pass “-“ as file name to read from standard input.
By default, gists are private; use ‘–public’ to make publicly listed ones.
gh gist create [<filename>... | -] [flags]
You can print out all of the aliases gh is configured to use using the following command.
gh alias list [flags]
I hope this helped you. You can connect with me on Twitter
Also, have look at my other blog:
Python 3.9: All you need to know about
Repository for Ultimate Resource in python. Drop a star if you find it useful! Got anything to add? Open a PR on the same!
Also, have a look at my other Blogs:
Resources: