Skip to content

Instantly share code, notes, and snippets.

@m-tmatma
Last active December 28, 2020 00:08
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 m-tmatma/05b9573ad64ef67eb3662d62bb6d0a20 to your computer and use it in GitHub Desktop.
Save m-tmatma/05b9573ad64ef67eb3662d62bb6d0a20 to your computer and use it in GitHub Desktop.
checkout by peco
#!/bin/sh
#
# please install peco in advance.
#
# sudo apt install -y peco
#
coremote () {
remotename=`echo $1 | sed -r "s#([^/]+)/.*#\1#"`
branchname=`echo $1 | sed -r "s#[^/]+/##"`
git branch | grep "..$branchname$"
if [ $? = 0 ]; then
git checkout $branchname
else
git checkout -b $branchname $remotename/$branchname
fi
}
alias cor='export -f coremote; coremote $(git branch -r | grep -v "/HEAD" | peco)'
colocal () {
branchname=`echo $1 | sed -r "s#^../##"`
git checkout $branchname
}
alias col='export -f colocal; colocal $(git branch | peco)'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment