Skip to content

Instantly share code, notes, and snippets.

@imjohnbo
Created September 23, 2020 18:04
Show Gist options
  • Save imjohnbo/bc1473705e24ea2b54cfe89383ca457a to your computer and use it in GitHub Desktop.
Save imjohnbo/bc1473705e24ea2b54cfe89383ca457a to your computer and use it in GitHub Desktop.
GitHub CLI examples

GitHub CLI

Manual | GitHub CLI

Examples

# Create public gist with test.txt
echo "test" > test.txt
gh gist create test.txt -d "a test" --public

# List open issues in the repo
gh issue list

# List closed issues assigned to imjohnbo
gh issue list -s "closed" -a "imjohnbo"

# Create issue (guided creation including templates)
gh issue create

# List open prs in the repo
gh pr list

# Checkout branch corresponding to pr number
gh pr checkout 490

# Create pr from current branch (guided creation including branch push)
gh pr create

# Clone repo
gh clone github/partner-engineering

# View preview of repo in Terminal (README)
gh repo view

# View repo in browser
gh repo view --web

# Create release
gh release create v1.2.3 -F changelog.md

# Last but not least... API
gh api repos/imjohnbo/get-actions-by-owner/releases

# More complex API example
gh api graphql -f query='
query Latest10 {
  organization(login: "imjohnbo-org") {
    auditLog(last: 10, query:"created: >=2010-04-14") {
      edges {
        cursor
        node {
          ... on AuditEntry {
            action
            actorLogin
            createdAt
            operationType
            __typename
          }
        }
        node {
          ... on Node {
            id
          }
        }
      }
    }
  }
}
'

Caveats

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