<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Oscar Calderon</title>
    <description>The latest articles on DEV Community by Oscar Calderon (@ocalde).</description>
    <link>https://dev.to/ocalde</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F270479%2Fe7fba503-14f3-4f78-afb6-a729f6f459e5.jpeg</url>
      <title>DEV Community: Oscar Calderon</title>
      <link>https://dev.to/ocalde</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ocalde"/>
    <language>en</language>
    <item>
      <title>Getting started with Github CLI</title>
      <dc:creator>Oscar Calderon</dc:creator>
      <pubDate>Thu, 17 Sep 2020 23:16:34 +0000</pubDate>
      <link>https://dev.to/ocalde/getting-started-with-github-cli-1028</link>
      <guid>https://dev.to/ocalde/getting-started-with-github-cli-1028</guid>
      <description>&lt;p&gt;GitHub (GH from now) just &lt;a href="https://github.blog/2020-09-17-github-cli-1-0-is-now-available/" rel="noopener noreferrer"&gt;released their first stable version of their CLI&lt;/a&gt; , the tool for managing and interacting with your GH repositories from your terminal. No more back &amp;amp; forth between the terminal &amp;amp; web browser for creating PRs, forking repositories, and whatnot. And if you or your company uses GH as their issue tracking tool, even better!&lt;/p&gt;

&lt;p&gt;I started to play with it as I find it useful to have an uninterrupted workflow entirely in my terminal. Usually, I have to fork repositories, create feature branches, do my stuff, commit-push, and then create PR to the original repository. Now I want to share my experience with you.&lt;/p&gt;

&lt;p&gt;Let's get hands on! Let's start by trying to create a repository in our GH account. We do so with the command &lt;code&gt;git repo&lt;/code&gt;.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

ocalderon@pop-os:~$ gh repo create main-repo


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;However, since we haven't authenticated in our CLI, we will get a message indicating to do so.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

ocalderon@pop-os:~$ gh repo create main-repo
Welcome to GitHub CLI!
To authenticate, please run 'gh auth login'.
You can also set the GITHUB_TOKEN environment variable, if preferred.


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Running the command &lt;code&gt;gh&lt;/code&gt; auth login will get us through a simple process to authenticate via web browser or using a generated token from GH webpage. &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

ocalderon@pop-os:~$ gh auth login
? What account do you want to log into? GitHub.com
- Logging into github.com
? How would you like to authenticate? Login with a web browser
! First copy your one-time code: 0123-ABCD
- Press Enter to open github.com in your browser... 


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Going with the web option will generate a unique code that we have to paste in the GH webpage that is opened by the command. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fsv89yu8gz6rmgu00dtp5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fsv89yu8gz6rmgu00dtp5.png" alt="Authenticating gh cli in GitHub"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then we review the permissions to give to the application, and we are in!&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

✓ Authentication complete. Press Enter to continue...
? Choose default git protocol SSH
- gh config set -h github.com git_protocol ssh
✓ Configured git protocol
✓ Logged in as ocalde


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now that we authenticated through &lt;code&gt;gh&lt;/code&gt;, we can try again to create our repository. It will ask us some questions, like repository visibility, or if we want to clone it in our current repository.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

ocalderon@pop-os:~$ gh repo create main-repo
? Visibility Private
? This will create 'main-repo' in your current directory. Continue?  Yes
✓ Created repository ocalde/main-repo on GitHub
? Create a local project directory for ocalde/main-repo? Yes
Initialized empty Git repository in /home/ocalderon/main-repo/.git/
✓ Initialized repository in './main-repo/'


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;And that's it. You can check in your GH account to see that the repository has been created successfully.&lt;/p&gt;

&lt;p&gt;Now, let's suppose we want to propose some changes in  &lt;a href="https://github.com/airbnb/javascript" rel="noopener noreferrer"&gt;airbnb/javascript&lt;/a&gt;  repository, created by Airbnb about Javascript best practices. For doing this, we need to fork the repository, do some changes, and then create a PR. We can do that from our terminal entirely, using &lt;code&gt;gh&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;We start by trying to fork the repository, using &lt;code&gt;gh repo&lt;/code&gt;.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

ocalderon@pop-os:~$ gh repo fork airbnb/javascript
? Would you like to clone the fork? Yes
Cloning into 'javascript'...
The authenticity of host 'github.com (140.82.112.3)' can't be established.
RSA key fingerprint is ....
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github.com,0.0.0.0' (RSA) to the list of known hosts.
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
failed to clone fork: exit status 128


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This happens because we haven't configured any SSH keys in our GH account. You can follow  &lt;a href="https://gist.github.com/adamjohnson/5682757" rel="noopener noreferrer"&gt;these steps to generate your SSH key&lt;/a&gt; , and configure it in your account.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5f0nmbv3gjzstfcny3re.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5f0nmbv3gjzstfcny3re.png" alt="configuring SSH key in GitHub"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once we are done with that, we can try again to fork the repo (we will be asked for the passphrase which we used to generate our SSH key):&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

ocalderon@pop-os:~$ gh repo fork airbnb/javascript
- Forking airbnb/javascript...
! ocalde/javascript already exists
? Would you like to clone the fork? Yes
Cloning into 'javascript'...
Warning: Permanently added the RSA host key for IP address '0.0.0.0' to the list of known hosts.
remote: Enumerating objects: 7862, done.
remote: Total 7862 (delta 0), reused 0 (delta 0), pack-reused 7862
Receiving objects: 100% (7862/7862), 3.13 MiB | 3.60 MiB/s, done.
Resolving deltas: 100% (4231/4231), done.
Updating upstream
From github.com:airbnb/javascript
 * [new branch]      gh-pages   -&amp;gt; upstream/gh-pages
 * [new branch]      master     -&amp;gt; upstream/master
 * [new branch]      shar--eslint-config-airbnb-prettier -&amp;gt; upstream/shar--eslint-config-airbnb-prettier
 * [new branch]      travis     -&amp;gt; upstream/travis
✓ Cloned fork


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Repository forked and cloned! We then can create a feature branch, do some changes, commit &amp;amp; push them, and once we are ready, we can create a PR, with &lt;code&gt;gh pr&lt;/code&gt;.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

ocalderon@pop-os:~$ gh pr create -B master -H ocalde:feature-branch 
Creating pull request for feature-branch into master in airbnb/javascript
? Title Some suggestions for Javascript documentation
? Body &amp;lt;Received&amp;gt;
? What's next? Submit
https://github.com/airbnb/javascript/pull/0000


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Like previous commands, we are asked for information like PR title, body (we can specify these when typing the &lt;code&gt;gh pr&lt;/code&gt; command). Also, I used &lt;code&gt;-B&lt;/code&gt; and &lt;code&gt;-H&lt;/code&gt; to specify the base &amp;amp; head branches, although I think it can ask for it as well if it isn't clear.&lt;/p&gt;

&lt;p&gt;If everything goes right, the PR is created automatically, and the command output gives you the URL to check it.&lt;/p&gt;

&lt;p&gt;And this is just a sample of what you can do using GH CLI. As I mentioned earlier, you can also handle the workflow of working with issues inside GH, and a lot of other things. You can check &lt;a href="https://cli.github.com/manual/" rel="noopener noreferrer"&gt;https://cli.github.com/manual/&lt;/a&gt; for a complete reference of all the available commands.&lt;/p&gt;

</description>
      <category>github</category>
      <category>introduction</category>
      <category>cli</category>
      <category>githubcli</category>
    </item>
  </channel>
</rss>
