Skip to content

Instantly share code, notes, and snippets.

@takesato
takesato / peco-select-branch.sh
Created July 31, 2014 06:38
branchを最終更新順に並べてpecoで選択してcheckoutする
function peco-switch-branch() {
local branch=$(
(
for i in `git branch | colrm 1 2|grep -v detached`;
do
echo `git log --date=iso8601 -n 1 --pretty="format:[%ai] %h" $i` $i;
done
) | sort -r|peco --query "$LBUFFER" | cut -f 5 -d" ")
if [ -n "$branch" ]; then
BUFFER="git checkout ${branch}"