tags:
- github
- git
permalink: what-is-github-cli
title: What is GitHub CLI?
date created: Monday, October 7th 2024, 9:34:09 am
date modified: Sunday, May 4th 2025, 11:44:55 am
GitHub CLI allows you to issue GitHub commands from your terminal.
Install.
brew install gh
Update.
brew update && brew upgrade gh
Authorize the application to connect to GitHub.
gh auth login
Use HTTPS for operations.
gh config set git_protocol https
If you receive errors when issuing commands, log into gh again and explicitly select HTTPS as the protocol: gh auth login
Refresh your authentication without logging in again.
gh auth refresh
Clone a repo.
gh repo clone "${owner_slash_repository}"
Set a default repo.
gh repo set-default "${owner_slash_repository}"
Run just gh repo set-default
to show a list of repos to choose from.
Update the active repository's description.
gh repo edit --description "😁 My repo description"
Change the active repository's visibility, accepting the consequences.
gh repo edit --visibility public --accept-visibility-change-consequences
List all PRs, open or closed.
gh pr list --state all
List my recently closed PRs.
gh pr list --state closed --author @me --repo "${owner_slash_repository}" --limit 5
Using jq, list the branch names of my recently closed PRs.
gh pr list --state closed --author @me --repo "${owner_slash_repository}" --limit 5 --json headRefName | jq -r '.[] | .headRefName'
Get all mergeable PRs.
#!/bin/bash
REPO=${1}
# List all open PR numbers.
pr_numbers=$(gh pr list --repo "$REPO" --state open --json number --jq '.[].number')
# Loop through each PR and check mergeable status.
for pr_number in $pr_numbers; do
pr_data=$(gh pr view $pr_number --repo "$REPO" --json mergeable,url,author,isDraft \
--jq '{mergeable: .mergeable, url: .url, author: .author.login, isDraft: .isDraft}')
mergeable_status=$(echo "$pr_data" | jq -r '.mergeable')
pr_url=$(echo "$pr_data" | jq -r '.url')
pr_author=$(echo "$pr_data" | jq -r '.author')
is_draft=$(echo "$pr_data" | jq -r '.isDraft')
if [ "$mergeable_status" == "MERGEABLE" ] && [ "$is_draft" == "false" ]; then
echo "$pr_author - #$pr_number - $pr_url"
fi
done