Getting Started with GitHub CLI
Tags: github, productivity, tutorial, go
Published: 2020-09-21 15:29:40

This post has orginally appeared in my [blog](https://qainsights.com/getting-started-with-github-cli/).
<!-- wp:paragraph -->
<p>Last week GitHub has released GitHub CLI which will improve the productivity among developers, product owners to interact with the repos and other administrator tasks. In this blog post, we will see about getting started with GitHub CLI, important commands etc.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>How to download GitHub CLI for Windows OS?</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>I primarily work on Windows platform; this blog post will feature only the Windows installation. For other operating systems, the process is pretty straight forward. I will add the relevant links for your reference.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Pay a visit to https://cli.github.com/ to download the GitHub CLI. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>For Windows, it would be an .msi file. But it is available via <a href="https://scoop.sh/" target="_blank" rel="noreferrer noopener">scoop</a> and <a href="https://chocolatey.org/" target="_blank" rel="noreferrer noopener">Chocolatey</a>.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Download the msi file and launch it. Follow the onscreen instructions, by default it will get installed in as shown below.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":7611,"sizeSlug":"large"} -->
<div class="wp-block-image"><figure class="aligncenter size-large"><img src="https://qainsights.com/wp-content/uploads/2020/09/image-9.png" alt="Getting Started with GitHub CLI" class="wp-image-7611"/><figcaption>Getting Started with GitHub CLI</figcaption></figure></div>
<!-- /wp:image -->

<!-- wp:heading -->
<h2>How to validate the installation?</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Launch a fresh command prompt or Windows terminal and type <code>gh --version</code>. You should get below prompt.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":7612,"sizeSlug":"large"} -->
<div class="wp-block-image"><figure class="aligncenter size-large"><img src="https://qainsights.com/wp-content/uploads/2020/09/image-10.png" alt="" class="wp-image-7612"/></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>If you go to the <strong>Environment Variables</strong>, you could see an entry for GitHub CLI in <strong>Path</strong>.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":7613,"sizeSlug":"large"} -->
<div class="wp-block-image"><figure class="aligncenter size-large"><img src="https://qainsights.com/wp-content/uploads/2020/09/image-11.png" alt="Environement Variables" class="wp-image-7613"/><figcaption>Environement Variables</figcaption></figure></div>
<!-- /wp:image -->

<!-- wp:heading -->
<h2>Logging in GitHub CLI</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>After successful installation, you need to log in into your GitHub account.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>To login</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p><code>gh auth login</code></p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":7614,"sizeSlug":"large"} -->
<figure class="wp-block-image size-large"><img src="https://qainsights.com/wp-content/uploads/2020/09/image-12.png" alt="Auth Login" class="wp-image-7614"/><figcaption>Auth Login</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Select the respective account and hit enter.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>You can login using web browser or token. Let us use a web browser.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":7615,"sizeSlug":"large"} -->
<figure class="wp-block-image size-large"><img src="https://qainsights.com/wp-content/uploads/2020/09/image-13.png" alt="Auth Mechanism" class="wp-image-7615"/><figcaption>Auth Mechanism</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>It will prompt you to copy the code  as shown below and hit enter and then go to the browser.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":7616,"sizeSlug":"large"} -->
<figure class="wp-block-image size-large"><img src="https://qainsights.com/wp-content/uploads/2020/09/image-14.png" alt="OTC" class="wp-image-7616"/><figcaption>OTC</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Follow the onscreen instructions, you will be good to go.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Basic interactions in GitHub CLI</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Once you back to the terminal, you need to set the default git protocol. </p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":7617,"sizeSlug":"large"} -->
<figure class="wp-block-image size-large"><img src="https://qainsights.com/wp-content/uploads/2020/09/image-15.png" alt="Git Protocol" class="wp-image-7617"/><figcaption>Git Protocol</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p><strong>To view a repo</strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><code>gh repo view QAInsights/PerfAction</code></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>To view a repo in the browser</strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><code>gh repo view QAInsights/PerfAction --web</code></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>To create a repo</strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><code>gh repo create</code></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>Change editor</strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>For Windows the default editor will be notepad. For macOS and Linux, you can set the editor <code>gh config set editor &lt;editor&gt;</code></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>Create a gist</strong></p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":7619,"sizeSlug":"large"} -->
<div class="wp-block-image"><figure class="aligncenter size-large"><img src="https://qainsights.com/wp-content/uploads/2020/09/image-17.png" alt="Gist Create" class="wp-image-7619"/><figcaption>Gist Create</figcaption></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p><strong>View gists</strong></p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":7620,"sizeSlug":"large"} -->
<div class="wp-block-image"><figure class="aligncenter size-large"><img src="https://qainsights.com/wp-content/uploads/2020/09/image-18-1024x42.png" alt="" class="wp-image-7620"/></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p><strong>Create issue</strong></p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":7621,"sizeSlug":"large"} -->
<div class="wp-block-image"><figure class="aligncenter size-large"><img src="https://qainsights.com/wp-content/uploads/2020/09/image-19.png" alt="Issue Create" class="wp-image-7621"/><figcaption>Issue Create</figcaption></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p><strong>View issues</strong></p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":7622,"sizeSlug":"large"} -->
<div class="wp-block-image"><figure class="aligncenter size-large"><img src="https://qainsights.com/wp-content/uploads/2020/09/image-20.png" alt="Issue List" class="wp-image-7622"/><figcaption>Issue List</figcaption></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p><strong>Close issue</strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><code>gh issue close &lt;issue-id&gt;</code></p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":7623,"sizeSlug":"large"} -->
<div class="wp-block-image"><figure class="aligncenter size-large"><img src="https://qainsights.com/wp-content/uploads/2020/09/image-21.png" alt="Close Issue" class="wp-image-7623"/><figcaption>Close Issue</figcaption></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p><strong>Create PR</strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><code>gh pr create --title &lt;&gt; --body&lt;&gt;</code></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>View PRs</strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><code>gh pr list</code></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>Merge PR</strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><code>gh pr merge [ &lt;number&gt;| &lt;url&gt; | &lt;branch&gt; ]</code></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>Close PR</strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><code>gh pr close [ &lt;number&gt;| &lt;url&gt; | &lt;branch&gt; ]</code></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>Create a release</strong></p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":7624,"sizeSlug":"large"} -->
<div class="wp-block-image"><figure class="aligncenter size-large"><img src="https://qainsights.com/wp-content/uploads/2020/09/image-22.png" alt="Create Release" class="wp-image-7624"/><figcaption>Create Release</figcaption></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p><strong>Delete a release</strong></p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":7625,"sizeSlug":"large"} -->
<figure class="wp-block-image size-large"><img src="https://qainsights.com/wp-content/uploads/2020/09/image-23.png" alt="Delete a release" class="wp-image-7625"/><figcaption>Delete a release</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>More commands at https://cli.github.com/manual/</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Conclusion</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Have you tried the new GitHub CLI? If not, you should try :)</p>
<!-- /wp:paragraph -->