Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save davidjguru/f1726fd8e384693c77279ac832e3e01e to your computer and use it in GitHub Desktop.
Save davidjguru/f1726fd8e384693c77279ac832e3e01e to your computer and use it in GitHub Desktop.
Working with Github CLI and derivative extensions

Introduction

Github CLI is a console tool for working on interactions with Github from terminal. This tool allow to add new extension by developing them and adding to the main gh prompt as sub-commands from your command line. Read More about how to implement custom Github CLI extensions.

For this example we use a private extension not available for public purposes but you can explore some others existing Github CLI extensions. See the list of available extensions at https://github.com/topics/gh-extension.

In order to follow the next steps just change [RESOURCE] by your marked extension.

Install Github CLI in Ubuntu / Debian

Add repository

type -p curl >/dev/null || (sudo apt update && sudo apt install curl -y)
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
&& sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \

Update system and install

sudo apt update \
&& sudo apt install gh -y

Working with Github CLI and custom derivative extensions

USAGE: $ gh <command> <subcommand> [flags]

Common Commands

CORE COMMANDS

  auth:        Authenticate gh and git with GitHub
  browse:      Open the repository in the browser
  codespace:   Connect to and manage codespaces
  gist:        Manage gists
  issue:       Manage issues
  pr:          Manage pull requests
  release:     Manage releases
  repo:        Manage repositories

Get more info about gh tool: $ gh -h

Log in Github from Github CLI

$ gh auth login
# Select: GitHub.com > HTTPS > y > Login from a web browser

Install custom extension for Github CLI

gh extension install provider/gh-[RESOURCE]

Clone an existing repository

$ gh repo clone cli/cli
Cloning into 'cli'...
$ cd cli
~/workspace/cli$

Create an Issue

$ gh issue create

Type: "<YOUR_NAME>_contribution" as the issue title > Enter > Enter

Create a branch

Copy the number located at the end of former URL. This number corresponds to the issue ID.
Now you can create a new working branch:

$ gh [RESOURCE] create-branch --issue <ISSUE_ID>

Note: Replace <ISSUE_ID> with the ID you copied from the URL. When prompted, select documentation as branch type and press Enter. Enter a description (for example: "Test contribution") and press Enter. Type Y to confirm the branch creation and press Enter. You receive a confirmation message that the branch has been created.

Add changes and commits

Now edit a single file and add some basic changes:

$ git add test-contributions/test-contributions.md

and create a new commit:

$ git commit -m "This is your contribution message"

Finally: add a new Pull Request

$ gh [RESOURCE] create-pr
# Select: Y > Y

This returns the URL of your pull request. Open the pull request URL from your web browser.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment