Gh: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
No edit summary
 
(16 intermediate revisions by the same user not shown)
Line 1: Line 1:
=External=
=External=
* https://cli.github.com/manual/
=Internal=
=Internal=
* [[GitHub_Procedures#gh_CLI|GitHub Procedures]]
* [[GitHub_Procedures#gh_CLI|GitHub Procedures]]
=Overview=
=Overview=
GitHub-specific CLI. Can be used to authenticate, clone repositories, etc.
GitHub-specific CLI. Can be used to authenticate, clone repositories, etc.
=Installation=
==Mac==
<syntaxhighlight lang='bash'>
brew install gh
</syntaxhighlight>
==Linux==
===With <tt>dnf</tt>===
<syntaxhighlight lang='bash'>
sudo dnf install -y 'dnf-command(config-manager)'
sudo dnf config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo
sudo dnf install -y gh
</syntaxhighlight>
===Download Release Binaries===
<syntaxhighlight lang='bash'>
wget https://github.com/cli/cli/releases/download/v2.9.0/gh_2.9.0_linux_amd64.rpm
rpm -i gh_2.9.0_linux_amd64.rpm
</syntaxhighlight>


=Authentication=
==Authentication Status==
<syntaxhighlight lang='bash'>
gh auth status --hostname enterprise.internal --show-token
</syntaxhighlight>
==Authenticate with a Personal Access Token==
<syntaxhighlight lang='bash'>
gh auth login --hostname enterprise.internal --with-token < mytoken.txt
</syntaxhighlight>
<syntaxhighlight lang='bash'>
gh auth login --hostname github.mycompany.com status --with-token < mytoken.txt
gh auth login --hostname github.mycompany.com status --with-token <<< "55...a8"
</syntaxhighlight>


==Configure Git to Use <tt>gh</tt> as Credential Helper==
<code>gh</code> repository cloning commands, and probably others, will continue to challenge for username and password, unless <code>git</code> is configured to use <code>gh</code> as credential helper.


⚠️ Note that this command must be executed '''after''' login.


<syntaxhighlight lang='bash'>
gh auth setup-git [--hostname enterprise.internal]
</syntaxhighlight>


gh auth <command> [flags]
==Logout==
<syntaxhighlight lang='bash'>
gh auth --hostname github.mycompany.com logout
</syntaxhighlight>


CORE COMMANDS
=Clone Repository=
  login:      Authenticate with a GitHub host
<syntaxhighlight lang='bash'>
  logout:     Log out of a GitHub host
gh repo clone <org>/<repo-name>
  refresh:    Refresh stored authentication credentials
</syntaxhighlight>
  setup-git:   Configure git to use GitHub CLI as a credential helper
==Full Sequence of Operations for Cloning, Including Authentication==
  status:     View authentication status
<syntaxhighlight lang='bash'>
gh auth login --hostname github.mycompany.com status --with-token < mytoken.txt
gh auth setup-git --hostname github.mycompany.com
gh repo clone <org>/<repo-name>
</syntaxhighlight>
==Troubleshooting==
===git@github.mycompany.com: Permission denied (publickey)===
Caused by the presence of <code>~/.gitconfig</code> with the following content:
<syntaxhighlight lang='text'>
url "git@github.mycompany.com:"]
insteadOf = https://github.mycompany.com/
</syntaxhighlight>

Latest revision as of 06:29, 3 May 2022

External

Internal

Overview

GitHub-specific CLI. Can be used to authenticate, clone repositories, etc.

Installation

Mac

brew install gh

Linux

With dnf

sudo dnf install -y 'dnf-command(config-manager)'
sudo dnf config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo
sudo dnf install -y gh

Download Release Binaries

wget https://github.com/cli/cli/releases/download/v2.9.0/gh_2.9.0_linux_amd64.rpm
rpm -i gh_2.9.0_linux_amd64.rpm

Authentication

Authentication Status

gh auth status --hostname enterprise.internal --show-token

Authenticate with a Personal Access Token

gh auth login --hostname enterprise.internal --with-token < mytoken.txt
gh auth login --hostname github.mycompany.com status --with-token < mytoken.txt
gh auth login --hostname github.mycompany.com status --with-token <<< "55...a8"

Configure Git to Use gh as Credential Helper

gh repository cloning commands, and probably others, will continue to challenge for username and password, unless git is configured to use gh as credential helper.

⚠️ Note that this command must be executed after login.

gh auth setup-git [--hostname enterprise.internal]

Logout

gh auth --hostname github.mycompany.com logout

Clone Repository

gh repo clone <org>/<repo-name>

Full Sequence of Operations for Cloning, Including Authentication

gh auth login --hostname github.mycompany.com status --with-token < mytoken.txt
gh auth setup-git --hostname github.mycompany.com
gh repo clone <org>/<repo-name>

Troubleshooting

git@github.mycompany.com: Permission denied (publickey)

Caused by the presence of ~/.gitconfig with the following content:

url "git@github.mycompany.com:"]
	insteadOf = https://github.mycompany.com/