Created
March 29, 2023 09:06
-
-
Save BKmetoff/4dfeb6493f86757996dfc3b1d886fce9 to your computer and use it in GitHub Desktop.
CLI git branch helper - operate on git branches.
This file contains 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
#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