GitHub/GH Client: Difference between revisions
< GitHub
(→api) |
|||
| (3 intermediate revisions by the same user not shown) | |||
| Line 10: | Line 10: | ||
Really really old version: | Really really old version: | ||
pip3 install gh | pip3 install gh | ||
=== winget === | |||
See [[WinGet#GitHub Client]] | |||
winget install --id GitHub.cli --source winget | |||
== Doc == | == Doc == | ||
https://cli.github.com/manual/gh_api | https://cli.github.com/manual/gh_api | ||
== Clone Repo == | |||
https: | |||
git repo clone [ORG_or_OWNER]/[REPO] | |||
ssh: | |||
git repo clone git@github.com:[ORG_or_OWNER]/[REPO] | |||
Set protocol to be ssh: | |||
gh config set git_protocol ssh | |||
== Auth == | == Auth == | ||
| Line 87: | Line 104: | ||
=== List === | === List === | ||
gh api /orgs/ORG/actions/runners | page 1 (pagination) | ||
gh api /orgs/ORG/actions/runners | |||
=== Installation Key === | |||
... | |||
== keywords == | == keywords == | ||
Latest revision as of 07:45, 21 February 2026
Github GH Client
Installation
https://github.com/cli/cli/releases/tag/v2.41.0
wget https://github.com/cli/cli/releases/download/v2.41.0/gh_2.41.0_linux_amd64.deb dpkg -i gh_2.41.0_linux_amd64.deb
Really really old version:
pip3 install gh
winget
winget install --id GitHub.cli --source winget
Doc
https://cli.github.com/manual/gh_api
Clone Repo
https:
git repo clone [ORG_or_OWNER]/[REPO]
ssh:
git repo clone git@github.com:[ORG_or_OWNER]/[REPO]
Set protocol to be ssh:
gh config set git_protocol ssh
Auth
gh auth status
Bad status:
$ gh auth status github.com X Failed to log in to github.com account YOUR-USER (/home/user/.config/gh/hosts.yml) - Active account: true - The token in /home/user/.config/gh/hosts.yml is invalid. - To re-authenticate, run: gh auth login -h github.com - To forget about this account, run: gh auth logout -h github.com -u YOUR-USER
Good status:
# gh auth status github.com ✓ Logged in to github.com account YOUR-USER (/home/user/.config/gh/hosts.yml) - Active account: true - Git operations protocol: ssh - Token: ghp_************************************ - Token scopes: 'admin:public_key', 'read:org', 'repo'
Login
gh auth login -h github.com
# gh auth login -h github.com ? What is your preferred protocol for Git operations on this host? SSH ? Upload your SSH public key to your GitHub account? /root/.ssh/github.pub ? Title for your SSH key: GitHub CLI ? How would you like to authenticate GitHub CLI? Paste an authentication token Tip: you can generate a Personal Access Token here https://github.com/settings/tokens The minimum required scopes are 'repo', 'read:org', 'admin:public_key'. ? Paste your authentication token: **************************************** - gh config set -h github.com git_protocol ssh ✓ Configured git protocol ! Authentication credentials saved in plain text ✓ SSH key already existed on your GitHub account: /root/.ssh/github.pub ✓ Logged in as YOUR-USER-NAME ! You were already logged in to this account
GH_TOKEN
PRIVATE_KEY='private_key.pem' APP_ID='12345' INSTALLATION_ID='54321' JWT=`./make-jwt.py $PRIVATE_KEY $APP_ID` GH_TOKEN=`curl -s --request POST --url "https://api.github.com/app/installations/$INSTALLATION_ID/access_tokens" --header "Accept: application/vnd.github+json" --header "Authorization: Bearer $JWT" --header "X-GitHub-Api-Version: 2022-11-28" | python -c "import sys, json; print(json.load(sys.stdin)['token'])"` echo "export GH_TOKEN=$GH_TOKEN" See make-jwt.pyapi
gh api ref: https://cli.github.com/manual/gh_apiAction Runners
https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28List
page 1 (pagination) gh api /orgs/ORG/actions/runnersInstallation Key
...keywords