git-branch-manager.sh
This file
Path
examples/git-branch-manager.sh
64 lines · 1.5 KiB · Shell
Last changed by
Not known.
History of this fileTake it
The walk stopped after 200 commits: lines older than 6837ed2 point at it.
feat(deps): bump github.com/charmbracelet/bubbletea from 0.27.0 to 1.0.0 (#661)dependabot[bot]before adoption6837ed2
lines 1–64why, one step back1#! /bin/sh23# This script is used to manage git branches such as delete, update, and rebase4# them. It prompts the user to choose the branches and the action they want to5# perform.6#7# For an explanation on the script and tutorial on how to create it, watch:8# https://www.youtube.com/watch?v=tnikefEuArQ910GIT_COLOR="#f14e32"1112git_color_text () {13 gum style --foreground "$GIT_COLOR" "$1"14}1516get_branches () {17 if [ ${1+x} ]; then18 gum choose --selected.foreground="$GIT_COLOR" --limit="$1" $(git branch --format="%(refname:short)")19 else20 gum choose --selected.foreground="$GIT_COLOR" --no-limit $(git branch --format="%(refname:short)")21 fi22}2324git rev-parse --git-dir > /dev/null 2>&12526if [ $? -ne 0 ];27then28 echo "$(git_color_text "!!") Must be run in a $(git_color_text "git") repo" 29 exit 130fi3132gum style \33 --border normal \34 --margin "1" \35 --padding "1" \36 --border-foreground "$GIT_COLOR" \37 "$(git_color_text ' Git') Branch Manager"3839echo "Choose $(git_color_text 'branches') to operate on:"40branches=$(get_branches)4142echo ""43echo "Choose a $(git_color_text "command"):"44command=$(gum choose --cursor.foreground="$GIT_COLOR" rebase delete update)45echo ""4647echo $branches | tr " " "\n" | while read -r branch48do49 case $command in50 rebase)51 base_branch=$(get_branches 1)52 git fetch origin53 git checkout "$branch"54 git rebase "origin/$base_branch"55 ;;56 delete)57 git branch -D "$branch"58 ;;59 update)60 git checkout "$branch"61 git pull --ff-only62 ;;63 esac64done