Skip to content

Instantly share code, notes, and snippets.

@agustin-tiendanube
Last active November 29, 2016 18:47
Show Gist options
  • Save agustin-tiendanube/0bfc55a0caa455d3233f269894ad3355 to your computer and use it in GitHub Desktop.
Save agustin-tiendanube/0bfc55a0caa455d3233f269894ad3355 to your computer and use it in GitHub Desktop.
#!/bin/bash
# sudo bash
re='^[0-9]+$'
if [[ "$1" =~ $re ]]; then
lines="$1"
else
lines=10
fi
branchs="$(git recent | tail -n $lines | nl)"
branchs_nf="$(git recent-nf | tail -n $lines | nl)"
echo "$branchs"
# Prompt which branch to checkout to
max="$(echo "$branchs" | wc -l)"
index=
while [[ ! ( "$index" =~ ^[0-9]+$ && "$index" -gt 0 && "$index" -le "$max" ) ]]; do
echo -n "Checkout to: "
read index
done
branch="$( echo "$branchs_nf" | sed -n "${index}p" | awk '{ print $NF }' )"
git co $branch
clear
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment