From 3affcf8ef6a736d9b0d9520ea8f58e3e3a3303ca Mon Sep 17 00:00:00 2001 From: Andrew Li Date: Thu, 7 Feb 2019 09:57:38 -0800 Subject: [PATCH] Added checkout remote search alias: cors --- bin/git-checkout-remote-search | 27 +++++++++++++++++++++++++++ home/gitconfig | 1 + 2 files changed, 28 insertions(+) create mode 100755 bin/git-checkout-remote-search diff --git a/bin/git-checkout-remote-search b/bin/git-checkout-remote-search new file mode 100755 index 0000000..c6b07e4 --- /dev/null +++ b/bin/git-checkout-remote-search @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +set -e + +counter=1 + +#echo "" # start with a newline + +echo -ne "Branch keyword: " +read n + +branches=($(git for-each-ref --format='%(refname:short)' | grep "origin.*$n" | awk -F '/' '{print $2}')) + +for name in ${branches[@]}; do + printf "%3s %s\n" "$counter." "$name" + let counter+=1 +done + +echo -ne "\nWhich branch number? " +read n + +if [[ $n =~ ^[0-9]+$ && $n -ge 1 && $n -le ${#branches[@]} ]]; then + git checkout ${branches[n-1]} +else + echo "Invalid selection!" + exit 1 +fi diff --git a/home/gitconfig b/home/gitconfig index ead61b0..acc5310 100644 --- a/home/gitconfig +++ b/home/gitconfig @@ -38,6 +38,7 @@ # checkout-specific aliases co = checkout coi = "!git-checkout-interactive" + cors = "!git-checkout-remote-search" cp = checkout --patch # merging