Created
September 11, 2017 04:22
-
-
Save m-nakamura145/09c6c9d4bc980affd2bc31bdf0cf4935 to your computer and use it in GitHub Desktop.
peco-git-branch-checkout
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
function peco-git-branch-checkout --description 'Check out a branch interactively' | |
set dir (basename $PWD) | |
git branch -a | peco --prompt="[$dir] Checkout branch:" --query="$argv" | tr -d ' ' > /tmp/branchname | |
set selected_branch_name (cat /tmp/branchname) | |
# Remove remote/ if its part of the branchname | |
switch $selected_branch_name | |
case '*-\>*' | |
set selected_branch_name (echo $selected_branch_name | perl -ne 's/^.*->(.*?)\/(.*)$/\2/;print') | |
case 'remotes*' | |
set selected_branch_name (echo $selected_branch_name | perl -ne 's/^.*?remotes\/(.*?)\/(.*)$/\2/;print') | |
end | |
set selected_branch_name (echo $selected_branch_name | sed -e 's/\*//g') | |
# Do the actual checkout | |
echo "Checking out $selected_branch_name" | |
git checkout $selected_branch_name | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment