Skip to content

Instantly share code, notes, and snippets.

@chrismatix
Created September 27, 2019 09:23
Show Gist options
  • Save chrismatix/f6ea4ed4c67a614f80dad415a80e0df2 to your computer and use it in GitHub Desktop.
Save chrismatix/f6ea4ed4c67a614f80dad415a80e0df2 to your computer and use it in GitHub Desktop.
Checkout branches recently checked out in git
checkout_recent() {
LASTN=${1:-5}
git checkout $(git reflog | egrep -io 'moving from ([^[:space:]]+)' | awk '{ print $3 }' | awk ' !x[$0]++' | egrep -v '^[a-f0-9]{40}$' | head -n $LASTN | fzf)
}
alias gre="checkout_recent"
@chrismatix
Copy link
Author

Add this to your .bash_profile or .zshrc to checkout branches recently checked out with git. Requires fzf for a nice selection.

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