Skip to content

Commit a19ae9e

Browse files
committed
prefer newer, local branches
1 parent 1ca5c57 commit a19ae9e

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

.githelpers

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,20 @@ reset_wildcard(){
9595

9696
# Accepts a pattern and switches to the first branch that matches it.
9797
switch_wildcard() {
98+
local all_branches=false
99+
while [[ "$1" =~ ^- && ! "$1" == "--" ]]; do case $1 in
100+
-a | --all )
101+
all_branches=true
102+
;;
103+
esac; shift; done
104+
if [[ "$1" == '--' ]]; then shift; fi
105+
98106
if [ -z "$1" ]; then
99107
echo "No pattern provided"
108+
elif [ "$all_branches" = true ]; then
109+
git branch --all --sort=-committerdate | sed 's|remotes/origin/||' | egrep "$1" | head -1 | xargs git switch
100110
else
101-
git branch -a | egrep "$1" | head -1 | xargs git switch
111+
git branch --sort=-committerdate | egrep "$1" | head -1 | xargs git switch
102112
fi
103113
}
104114

0 commit comments

Comments
 (0)