Setting up GitHub Repo using GitHub CLI

Sanyam
3 min readSep 7, 2022

--

GitHub

In this article, we will set up an entire GitHub repo using a terminal using GitHub CLI and do various operations on it.

Installation

For Mac and Linux, follow the instructions provided here

  • After installation, spin up the terminal of your choice. I’m using Hyper.
    And run the following command to verify if the installation was successful.
$ gh --version

Creating the Repository

  • Create a directory in your preferred location and add some dummy files to it.
  • cd into the directory using your terminal and initialize git.
$ git init
  • First, you need to create a session and log in using your GitHub credentials. Type the following command in your terminal.
$ gh auth login
  • Choose the preferred service and continue with it. I’m using GitHub.com for this example.
  • Proceed with the instructions and create your session.
GitHub CLI log in
  • You should see the following page after successful Sign-In
  • Now, head back to your terminal, and let’s create the repo. Type the following command to do so.
$ gh repo create
  • This will provide you with two options, either create a new repo (which we’ll select) or pushing an existing local repo to GitHub.
  • Give your repo a name and proceed with the further instructions
  • Now, head over to GitHub and you can see the latest repo created.
  • Next, you can add and commit your changes to this repo using the CLI and push it onto the repo subsequently.

Other Important CLI commands

  • Deleting the repository
$ gh repo delete <reponame>

BUT, in order to utilize this command, you need to refresh the session state. Type the following command in your terminal and refresh your current session

gh auth refresh -h github.com -s delete_repo

Proceed with the instructions and you should see the following screen on successful state refreshing.

Now, proceed with the command gh repo delete <reponame> and you should be able to proceed with it.

  • Logging out of the current session
$ gh auth logout

This will delete the session and will log you out.

--

--

Sanyam

full stack web developer and music producer from India. specialized in ReactJS, NextJS, Firebase, Sanity.io and other various front/back-end libraries!