Skip to content

Instantly share code, notes, and snippets.

@Guthers
Last active May 16, 2024 01:38
Show Gist options
  • Save Guthers/f9199534ba285b3e3faacceefb1c87a4 to your computer and use it in GitHub Desktop.
Save Guthers/f9199534ba285b3e3faacceefb1c87a4 to your computer and use it in GitHub Desktop.
Git Switch to latest branches
#!/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