Skip to content

Instantly share code, notes, and snippets.

@Fatpandac
Created December 7, 2023 06:43
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 Fatpandac/d0442e5cc365d21daf28e75204f87fe7 to your computer and use it in GitHub Desktop.
Save Fatpandac/d0442e5cc365d21daf28e75204f87fe7 to your computer and use it in GitHub Desktop.
Quick checkout and delete branch by fzf
gitSelectBranch() {
selected=$(git branch -a | grep -v "*" | fzf | sed -e "s/remotes\/origin\///" | sed 's/^\s*\|\s*$//g')
echo "$selected"
}
gitSelectBranchOprateFactory() {
comd=$1
branch=$2
if [ -z $2 ];then
selected=$(gitSelectBranch)
echo "$selected"
if [ -z != $selected ]; then
eval "$1 $selected"
fi
else
eval "$1 $2"
fi
}
unalias gc
gc() {
comd="git checkout"
gitSelectBranchOprateFactory $comd $1
}
unalias gbd
gbd() {
comd="git branch -D"
gitSelectBranchOprateFactory $comd $1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment