Skip to content

Instantly share code, notes, and snippets.

View matcouto's full-sized avatar

Mateus Couto matcouto

  • Sydney Australia
View GitHub Profile
@matcouto
matcouto / branch_switcher.sh
Last active May 3, 2024 00:20
Switch between your most recently used branches.
#!/bin/bash
# Get the last 5 used branches
branches=$(git reflog | grep -o 'checkout: moving from [^ ]*' | sed 's/checkout: moving from //' | awk '!seen[$0]++' | head -5)
# Check if branches were found
if [ -z "$branches" ]; then
echo "No branches found."
exit 1
fi