Skip to content

Instantly share code, notes, and snippets.

@fsimonis
Last active December 9, 2021 14:50
Show Gist options
  • Save fsimonis/b72f1c9475e5548740120c5b39dc22ad to your computer and use it in GitHub Desktop.
Save fsimonis/b72f1c9475e5548740120c5b39dc22ad to your computer and use it in GitHub Desktop.
Quick branch/PR switcher for GitHub based on fzf

Script based on github-cli and fzf to switch branches and PRs super quickly.

Calling it with arguments will forward them to gh pr checkout.

Calling it with no arguments displays a fuzzy search of PR numbers and titles. Selecting an entry will checkout that PR.

#! bash
if [ $# -eq 0 ]; then
gh pr list -L 999 --json number,title -t \
'{{range .}}{{tablerow (printf "#%v" .number | autocolor "green") .title}}{{end}}' \
| fzf --ansi \
| sed "s/^#\([0-9]\+\).*/\1/" \
| xargs gh pr checkout
else
gh pr checkout $@
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment