Skip to content

Instantly share code, notes, and snippets.

@BKmetoff
Created March 29, 2023 09:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BKmetoff/4dfeb6493f86757996dfc3b1d886fce9 to your computer and use it in GitHub Desktop.
Save BKmetoff/4dfeb6493f86757996dfc3b1d886fce9 to your computer and use it in GitHub Desktop.
CLI git branch helper - operate on git branches.
#bin/bash
fuzz="fzf --height=40% --border --color=light --cycle --margin=15% --padding=1 --no-info"
print_columns="pr -2 -t -w 100"
operations=`echo "checkout delete create list remote-list remote-checkout" | tr ' ' '\n'`
selected_operation=`printf "$operations" | $fuzz`
if [[ "$selected_operation" == "remote-list" ]]; then
echo "\n Remote branches, not merged in main:\n"
git branch -r --no-merged main | $print_columns
fi
if [[ "$selected_operation" == "checkout" ]]; then
branch=`git branch | $fuzz | xargs`
git checkout $branch
fi
if [[ "$selected_operation" == "remote-checkout" ]]; then
branch=`git branch -r | $fuzz | xargs`
git checkout $branch
fi
if [[ "$selected_operation" == "list" ]]; then
echo "\n Local branches:\n"
git branch | $print_columns
fi
if [[ "$selected_operation" == "delete" ]]; then
branch=`git branch | $fuzz | xargs`
git branch -d $branch
fi
if [[ "$selected_operation" == "create" ]]; then
read -p "branch name: " new_branch
git checkout -b "$new_branch"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment