Last active
May 16, 2024 01:38
-
-
Save Guthers/f9199534ba285b3e3faacceefb1c87a4 to your computer and use it in GitHub Desktop.
Git Switch to latest branches
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# To use the following command put this at the bottom of your .bashrc then run `gits` | |
alias git_latest="git for-each-ref --sort=-committerdate --format='%(refname:short)' refs/heads" | |
gits() { | |
top_n=10 | |
if [ $# -eq 1 ] ; then | |
top_n=$1 | |
fi | |
select branch in $(git_latest | head -n "${top_n}") | |
do | |
echo "Switching to $branch" | |
git switch "$branch" | |
break | |
done | |
echo "" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment