Github just released it’s own Command-Line Interface (CLI) so developers can now do everyday GitHub tasks from the terminal. Yay! This means no more squiggling around the UI. With this new CLI, you can now view, create, clone, or fork repositories, create, view, and edit gists, you can also work with pull requests and issues right from the terminal. Isn’t that awesome? The motive behind this CLI is to move all of the developer workflow right to the terminal where we were already working with git. Now you might ask, . The CLI is meant to integrate well with git, which means your trusty old git isn’t going anywhere. Rather this was one of the motives behind the creation of the GitHub CLI, bringing all your tools to one place to avoid context switching. will it replace the git CLI? The answer is no which is an open-source extension to command-line git, maintained by a GitHub employee, that lets you do everyday GitHub tasks without ever leaving the terminal. Sounds pretty familiar eh? Hub already offers a lot of the things that the Github CLI brings to the table. But wait! doesn’t something like this already exists? Yes, yes it does. A GitHub wrapper called hub So why is GitHub Reinventing the Wheel? The GitHub team mentions that the primary reason they didn’t build on top of was that they didn’t want to wrestle with the 10 odd years of design decisions that hub went through which weren’t really focused on GitHub workflows. They also because that might upset the already established user base which used hub on a daily basis. They addressed this in a lot more detail in their . hub didn’t want to change hub significantly docs So enough talk, let’s see how it actually works. By the end of this article, you should be well on your way to integrating the GitHub CLI in your workflow. Installation The first step is installing the CLI. To do that simply follow the for your operating system given on their official page. install instructions Setting Up After installing, the next thing that you have to do is authenticate your Github account. Do that by entering the following command: gh auth login You’ll be asked to select the type of account that you want to login with, select accordingly. After that, you will be given a secret code that you’ll need to enter in the prompted browser window. Successful login should look something like this: If you need to refresh your credentials anytime, you can do it by: gh auth resh ref Check your authentication by: gh auth status Set Your Editor You can set your editor of choice to open files for cases when gh will prompt you to edit a file. Set it by entering: gh editor editorName config set Replace with the name of your editor like emacs, vim, nano etc. editorName Get Tab Completions For gh Commands You might have noticed that your usual tab completions don’t work, to get it to work, paste the following code in your ~/.bash_profile: eval "$(gh completion -s bash)" Reload your terminal and boom! you can tab-complete now. Repositories Now let’s learn creating, forking, cloning, and viewing repositories. Creating repositories There are various ways of creating a repository using gh. Make sure you are logged in and are navigated into the projects directory, then enter: gh repo create This will create a repository with the name of your directory under your account. 1. : With a specific name gh repo repoName replace with the name that you want to give to your repository. repoName 2. : Under an organization gh repo orgName/repoName create Replace with the name of your organization and with the name of the repository as usual. orgName repoName Set Flags For Additional Options You can also set flags in the command to give additional features to your repository like making it public or private. Here is a list of all the flags that you can give to your repo: -y, --confirm Confirm the submission -d, --description "string" Description of your repo --enable-issues Allow people to add issues(default value is true) --enable-wiki Enable wiki in the new repository (default true) -h, --homepage "string" Repository home page URL --internal Make the repository internal --private Make the repository private --public Make the repository public -t, --team "string" The name of the organization team to be granted access -p, --template "string" Make the new repository based on a template repository So for example if I want to create a repository with the under the and I want to set it to with I would enter: name of Python organization Monty private issues disabled, gh repo Monty/Python -- --enable-issues= create private false As simple as that. Cloning Repositories You can clone repositories more simply in gh by using its unique syntax: owner/repo gh repo /repo clone owner Replace with the account name of the owner and with the repository name. owner repo You can also clone repositories using Github URLs like before: gh repo clone <code = ><a = = = = = >https://github.com/cli/cli</a></code> class "markup--code markup--pre-code" href "https://github.com/cli/cli" data-href "https://github.com/cli/cli" class "markup--anchor markup--pre-anchor" rel "noopener" target "_blank" Forking Repositories You can fork repositories in 3 ways: 1. Without Giving Arguments: gh repo fork This will create a fork of the repository that you are currently navigated into on your Github account. 2. Giving Arguments: gh repo fork /repo user Replace with the username and with the repo name. user repo 3. With Flags: You can provide flags like and to skip prompts. The flags take a value either true or false. ‘ — remote’ ‘ — clone’ gh repo fork user/repo = = --clone true --remote true This will also clone the forked repository and also set an upstream remote, all in one line. Viewing Repositories Now let’s talk about viewing repositories. You can view the of any Github repository right in your terminal: description and README gh repo /repo view user This will look something like this: Pretty neat! You can also choose to view the repo in your browser by providing the ‘ — web’ or the ‘ -w’ flag. gh repo /repo view user --web Providing no arguments will open the repo that you are currently in: gh repo view Gists We can view, list, create, and edit gists. Creating Gists To create a gist write: gh gist create --public example.cpp The public flag will make the gist public. Keep in mind that so in the absence of a flag, your gist will be private. the default value is private To to the gist use the flag: give a description -d gh gist create --public example.cpp -d "An example program in c++" in your gist by separating them with a whitespace: Add multiple files gh gist create example app hello.py .cpp .js You can also by using a hyphen (-) in place of the file name: write a gist in the terminal gh gist - create Listing your Gists To view all your gists enter: gh gist list You can also give flags like or to list only your public gists or secret gists. “ — public” “ — secret” Editing Gists You can edit gists using the command: gh gist gistID edit or alternatively gh gist gistURL edit Needless to say, in the above commands replace ‘gistID’ with your, well… gist ID and “gistURL” with the URL of your gist. You can get your gist id by first listing the gist by: gh gist list And then copying the 32 character code displayed there you can copy the code from the URL of your gist, it would be the last part of your URL. or But here’s something tricky... although I recommend using gistID because of its simplicity, if you plan to use the gist URL, simply it will give you a 404 something like this: copying and pasting the URL of your gist won’t work, Four Oh Four To make it work you need to remove your username from the URL and then run the command. If done correctly, your gist should be opened in the editor that you set earlier. Viewing a gist You can view a gist using: gh gist gistID view or gh gist gistURL view If you want to without rendering markdown put the flag at the end. View the gist in a browser by the flag view it raw “ — raw” “ — web” . Pull Requests Now we are going to tackle working with using gh. Make sure that you are navigated into the project directory. pull requests Note: As a general rule of thumb use the flag “-R owner/repo” or “ — repo owner/repo” with all of the commands below if you want to select a repository other than the one that you are navigated into. Listing Pull Requests You can list pull requests on a project by using: gh pr list This will list all your . open pull requests If you want to list the or pull requests, you can do so by adding the flag as shown below: closed merged ‘ — state “string”’ gh pr list --state closed To see give the argument to the flag: all of the pull requests ‘all’ ‘state’ gh pr list --state all Here are some very useful flags that you can use with this command: <code class= >- , --assignee Show pull requests by assignee -B, --base Filter by base branch - , --label strings Filter by labels -L, --limit Maximum of fetch (default -s, --state Filter by state: { |closed|merged| } (default ) - , --web Open the browser the pull requests</code> "markup--code markup--pre-code" a string all an <br> string <br> l <br> int number items to 30 <br> string open all "open" <br> w to list Viewing Pull Requests Quickly view a pull request’s information: gh pr view Using this without any arguments will display the pull requests on the current branch that you are navigated into. Use git checkout first to checkout to a branch name and view its pull request. You can give the or a or a to view a specific pull request: pull request number URL branch gh 5 pr view gh master pr view gh urlOfPullRequest pr view Creating a Pull Request To create a pull request on a repository enter: gh pr create Make sure that you are in the project directory and are navigated to the branch that you want to push to the origin master. The above command will display some prompts asking you to specify the title and body of your pull request. If the branch isn’t pushed to a git remote or some files in the branch haven’t been pushed then you will be prompted to enter the location where you want the branch to be pushed, gh will also give you an option to fork the base repository. If you don’t want to create a pull request interactively then you can give flags with the command to provide the information there: gh pr create --title "Bumped to 2.0" --body "Updated the version" Assign the pull request to someone: gh pr create --assignee username Request a pr review from someone: gh pr create --reviewer username Select a branch in which you want your code to be merged: gh pr create --base branchName Here are all of the flags that you can use while creating a pull request: -a, --assignee login Assign people by their login -b, --body string Body for the pull request -d, --draft Mark pull request as a draft -f, --fill Skip the prompt for title/body and use commit info -H, --head branch The branch that contains commits for your pull request (default: current branch) -l, --label name Add labels by name -m, --milestone name Add the pull request to a milestone by name -p, --project name Add the pull request to projects by name -t, --title string Give the pull request a title. -w, --web Create the pr in a web browser Checking Out Pull Requests If you want to test a pull request to make sure that it works fine and doesn’t break anything before merging it into master you can do it easily using this command: gh pr checkout prURL prNumber or branch or You can either provide the of the pull request or the of the pull request or the . URL number branch This will navigate you to the branch of the pull request with all the files loaded in your working directory and ready to go. From here you can test to your heart’s content. You can do a quick ‘ls’ command to view the contents of the pull request. To go back to the master branch simply use git checkout. git checkout master You can choose to merge or close the pull request from there. Merging a Pull Request If you want to merge the pull request after testing it then you can use: gh pr prNumber prURL branch merge or or This will merge the pull request into the origin master branch, and will from both the local and the remote repositories. If you want to retain the branch use: by default delete the head branch of the pull request gh pr merge prNumber --delete-branch=false Here are some more flags that you can use with pr merge: -m, --merge Merge the commits with the base branch -r, --rebase Rebase the commits onto the base branch -s, --squash Squash the commits into one commit and merge it into the base branch Closing a Pull Request If you want to close a pull request you can use: gh pr prNumber prURL branchName close or or If you want to from the local and the remote repository then use the “ — delete-branch” flag. delete the branch of the pull request Viewing Changes in a Pull Request You can view the changes proposed by the pull request by: gh pr prNumber prURL branchName diff or or Check the Status of a Pull Request Check the status of the pull requests in your current branch: gh pr status This command will also show you the status of your open pull requests created by you and also the status of the pull requests that you have to review. Something like this: Mark a pull request ready for review gh pr ready prURL prNumber branch or of Reopen a closed pull request gh pr reopen prNumber prURL branch or or Review a pull request gh pr review prNumber prURL branch or or The flags here are: -a, --approve Approve the pull request -b, --body string Specify the body of a review -c, --comment Comment on a pull request -r, --request-changes Request changes on a pull request Issues The last thing in this tutorial that we are going to learn is working with issues. Listing the Issues gh issue // issues list list all You can put flags to filter the results. -a, --assignee string Filter by assignee -A, --author string Filter by author -l, --label strings Filter by labels -L, --limit int Maximum number of issues to fetch (default 30) --mention string Filter by mention -m, --milestone number Filter by milestone number or `title` -s, --state string Filter by state: {open|closed|all} (default "open") -w, --web Open the browser to list the issue(s) Viewing an issue gh issue issueNumber issueURL view or Creating an issue To create an issue interactively with prompts use: gh issue create To skip the prompts you can use the following flags -a, --assignee login Assign people by their login -b, --body "string" Add the body of the issue -l, --label name Add labels by name -m, --milestone name Add the issue to a milestone by name -p, --project name Add the issue to projects by name -t, --title "string" Supply a title. -w, --web Create an issue in the browser View the Status of Issues in a Repository gh issue status Closing and Reopening an issue gh issue issueNumber issueURL close or gh issue reopen issueNumber issueURL or Getting Help If you forget any command or its flags or if you want to consult the documentation quickly then you can always use the flag to view the documentation of the command in the terminal itself. “ — help” Conclusion I found the CLI to be intuitive and quite easy to use, I guess its time to say goodbye to the UI for good. By now you should be ready to integrate the Github CLI into your day-to-day workflow and perform all of your UI actions in the terminal. I have tried my best to cover all of the use cases that one might run into but still if you have any questions feel free to hit me up. Wish you a happy and productive coding journey :) Link to the official . CLI manual Fork me on :)️ Github