Tips & advice related to GitHub specific features of git, gpg, and development.
- 
v 0.1.0 Minor (see Status & Versioning & Copyright & License)
 
- General 'gh` Tips
 - install
- First time auth with GitHub and create initial credentials and configuration
 - Set local script variable $GH_TOKEN to the 
ghtoken - GitHub auth login using an existing token
 - status
 - function to check login status in script
 - logout
 - Quickly create a GitHub repo (skip confirmation, private, turn off unecessary features)
 - list all personal repos (all, no forks, no archives, no private)
 
 gh gisttips
- list all of your public gists
 - list private gists
 - pick a gist from list in cli and view on web
 - Quick create private gist
 - view a gist in markdown gist in raw mode
 
- macOS: 
brew install gh 
gh auth loginGH_TOKEN=$(gh auth status -t 2>&1 | grep "Token:" | gsed -e 's/^.*: //g')
git credential reject <<<"url=https://github.com"
echo $GH_TOKENgh auth login --with-token <<<$(cat $HOME/path/to/token.txt | head -1)gh auth status -t# hostname is necessary just in case you are logged into the CLI
# GitHub enterprise instance
if ! (gh auth status --hostname "github.com" > /dev/null 2>&1); then
  echo "Not logged into github".
  echo "Please run: gh auth login"
  exit 1
figh auth logoutgh repo create -y --private --enable-issues=false --enable-wiki=false -d "Description" REPOAdditional options:
  ORGANIZATION/REPO                  Specificy Organization (without ORGANIZATION/ will be personal)
  -h, --homepage URL          Repository home page URL
  -t, --team name             The name of the organization team to be granted access
  -p, --template repository   Make the new repository based on a template repositorygh repo list --limit 1000 --source --no-archived --public Add gh repo list ORGANIZATION --limit 1000 … to list repos in organizaiton
while read list_line; do read repo description visibility datetime <<< "$list_line" && gh repo clone "$repo"; done < <(gh repo list --source --no-archived --public | cat)while read list_line; do read repo description visibility datetime <<< "$list_line" && gh repo clone "$repo"; done < <(gh repo list ORGANIZATION -source --non-archived --public | cat)- OR
 
#!/bin/bash
# clone-repos.sh
# Requires `gh` --> https://cli.github.com/
# Usage:
# $ ./clone-repos.sh some_org target_dir
# Cloning into 'target_dir/some_repo'...
gh repo list "$1" --limit 1000 -source --non-archived --public | while read -r repo _; do
  repo_name=$(echo "$repo" | grep -oP "^$1\K.*")
  gh repo clone "$repo" "$2$repo_name"
done- gh cloner function (to be rewritten)
 
(from https://gist.github.com/jaysonsantos/895c73fe011241b6e250c98f156ddb4f
function gclone() {
    local organization
    local repositories
    organization="$1"
    repositories="$(gh repo list -L 1000 "$organization" | fzf --multi --cycle | awk '{print $1}')"
    for repository in $repositories; do
        echo "Cloning $repository"
        gh repo clone "$repository"
    done
}CORE COMMANDS
  checkout:   Check out a pull request in git
  checks:     Show CI status for a single pull request
  close:      Close a pull request
  comment:    Create a new pr comment
  create:     Create a pull request
  diff:       View changes in a pull request
  edit:       Edit a pull request
  list:       List and filter pull requests in this repository
  merge:      Merge a pull request
  ready:      Mark a pull request as ready for review
  reopen:     Reopen a pull request
  review:     Add a review to a pull request
  status:     Show status of relevant pull requests
  view:       View a pull request
  
  A pull request can be supplied as argument in any of the following formats:
  - by number, e.g. "123";
  - by URL, e.g. "https://github.com/OWNER/REPO/pull/123"; or
  - by the name of its head branch, e.g. "patch-1" or "OWNER:patch-1".gh pr list
  -a @me          `# my prs` \
  --state closed  `# open/closed/all` \
  -w              `# show in webbrowser` \gh pr list --author @me
gh pr list --assignee @me
gh pr list --label bug --label "priority 1"
gh pr list --search "status:success review:required"
gh pr list --web
gh pr create --title "The bug is fixed" --body "Everything works again"
gh pr create --reviewer monalisa,hubot  --reviewer myorg/team-name
gh pr create --project "Roadmap"
gh pr create --base develop --head monalisa:feature
gh pr checkout 123
gh pr checkout 123 --force
gh pr checkout 123 --detach
gh pr checkout 123 --recurse-submodules
gh pr edit 123 --title "I found a bug" --body "Nothing works"
gh pr edit 123 --add-label "bug,help wanted" --remove-label "core"
gh pr edit 123 --add-reviewer monalisa,hubot  --remove-reviewer myorg/team-name
gh pr edit 123 --add-assignee @me --remove-assignee monalisa,hubot
gh pr edit1 23 --add-project "Roadmap" --remove-project v1,v2
gh pr edit 123 --milestone "Version 1"
gh pr merge 123 --merge --comment --body "merged old with new"
gh pr merge 123 --rebase
gh pr merge 123 --squash
gh pr ready 123
gh pr review --approve
gh pr review --comment --body "interesting"
gh pr review 123
gh pr review 123 --request-changes --body "needs more ASCII art"
gh pr review 123 --request-changes --body-file review.md
gh pr close 123 --delete-branch
gh pr diff [<number> | <url> | <branch>] [flags]
gh pr checkout 123# For Bash or ZSH
function gh-pr() {
    branch=`git rev-parse --abbrev-ref HEAD`
    prNum=`gh pr list | grep '$branch' | grep -o '[0-9]\+' | head -1`
    gh pr view $prNum
}#!/bin/bash
set -e
if ! which gh 2>&1 > /dev/null; then
    echo 'Missing gh cli'
    exit 1
fi
if [ $# -eq 0 ]; then
    echo "usage: $0 <github query>"
    echo "Read more in https://docs.github.com/en/search-github/searching-on-github/searching-issues-and-pull-requests"
    exit 0
fi
# summary
gh pr list --search "$*"
echo "Relevant commands: view, diff, checks, comment, review, edit"
echo "Type <command> help for more info"
echo "Press C^D to go to next PR."
echo ""
set +e
# repl on each PR
for pr in $(gh pr list --search "$*" --json number -q ".[].number"); do 
    gh pr view --comments $pr
    while read -p "gh pr (#$pr)> " args; do gh pr $args $pr; done
    echo
donegh gist list --publicgh gist list --secretclear; gh gist view --webgh gist create mygisttopic.mdclear; gh gist view -r $(gh gist list --public | grep ".md" | cut  -f1 | head -1)  create:     Create a new gist
    -d, --desc string       A description for this gist
    -f, --filename string   Provide a filename to be used when reading from STDIN
    -p, --public            List the gist publicly (default: private)
    -w, --web               Open the web browser with created gist
  delete:     Delete a gist
  edit:       Edit one of your gists
    -a, --add string        Add a new file to the gist
    -f, --filename string   Select a file to edit
  list:       List your gists
    -L, --limit int   Maximum number of gists to fetch (default 10)
    --public      Show only public gists
    --secret      Show only secret gists
  view:       View a gist
    -f, --filename string   Display a single file from the gist
    --files             List file names from the gist
    -r, --raw               Print raw instead of rendered gist contents
    -w, --web               Open gist in the browser