Setting Up GitHub CLI


Setting Up GitHub CLI (gh)

1. Installation

macOS:

brew install gh

Linux:

  • Download the .deb or .rpm file from the GitHub CLI release page.

  • Install with sudo dpkg -i gh_*_linux_amd64.deb or sudo yum install gh_*_linux_amd64.rpm based on your distro.

Windows:

  • Download the MSI installer from the GitHub CLI release page and execute it.

  • Alternatively, you can install using Chocolatey with choco install gh.

2. Authentication

After installation, you'll need to authenticate:

gh auth login

Follow the prompts. You can log in with a browser or paste an authentication token.


Powerful Things GitHub CLI Can Do

1. Issues & PR Management

  • View issues: gh issue list

  • Create an issue: gh issue create

  • View pull requests: gh pr list

  • Create a pull request: gh pr create

  • Checkout PRs: gh pr checkout PR_NUMBER

2. Repositories

  • Create a new repository: gh repo create [name]

  • Clone a repository: gh repo clone [repository]

  • View the repo in the browser: gh repo view [--web]

3. Gists

  • Create a gist: gh gist create [file1, file2, ...]

  • List your gists: gh gist list

  • View a gist: gh gist view gist_id

4. Aliases

You can create shortcuts for commands you frequently use.

Example:

Now, gh co PR_NUMBER will checkout the specified PR.

5. Extensions

GH CLI is extensible, and you can add functionality through extensions. Find extensions on GitHub or make your own.

To install an extension:


Explore Further

The above commands are just the tip of the iceberg. GitHub CLI is versatile and packed with features. To dive deeper into any command or to explore others:

Now, you're equipped with the knowledge to harness the full power of GitHub right from your terminal. The world (or at least your repositories) is your oyster! Happy coding!

Last updated