Skip to content

Instantly share code, notes, and snippets.

@rolandcrosby
Created March 1, 2022 22:31
Show Gist options
  • Save rolandcrosby/03a4465c0f463911c9941863794be111 to your computer and use it in GitHub Desktop.
Save rolandcrosby/03a4465c0f463911c9941863794be111 to your computer and use it in GitHub Desktop.
Git “most recently used” branch listing command
#!/usr/bin/env bash
branch_file="$(mktemp)"
git branch -l --format '%(refname:lstrip=2)' > "$branch_file"
git reflog --format='%D' | sed -e 's/, /\n/g' | awk '$0 && !x[$0]++ {print}' | grep -x -F -f "$branch_file" | head -n 10 | tac
rm "$branch_file"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment