Skip to content

Instantly share code, notes, and snippets.

@bastos
Created February 8, 2023 01:13
Show Gist options
  • Save bastos/f41a47a1d201ba93feb46a6fe10434aa to your computer and use it in GitHub Desktop.
Save bastos/f41a47a1d201ba93feb46a6fe10434aa to your computer and use it in GitHub Desktop.
Bash script to select a branch and checkout using charmbracelet/gum
#!/bin/sh
if ! [ -d .git ]; then
echo "This directory does not have a Git repository"
exit 1
fi
repository=$(git branch | awk '{print $NF}' | sort -r | gum filter --limit=1)
if [ -z "$repository" ]; then
echo "No branch selected"
exit 1
else
git checkout $repository
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment