From 18c56bf00d19b2f476cb459c8b599cc3a32c1064 Mon Sep 17 00:00:00 2001 From: Gabe Berke-Williams Date: Fri, 11 Aug 2017 23:57:56 -0700 Subject: [PATCH] Check out local branches that track remote Let's say there's a branch at remotes/origin/foo, and no foo branch locally. `git checkout foo` will checkout a local branch set up to track the remote foo branch. I have never, ever wanted to do `git checkout remotes/origin/foo` and get one of those weird non-local branches. So, display branches as `remotes/origin/foo`, but then chop it down to `foo` before passing to `git checkout`. --- zshrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zshrc b/zshrc index ca616ce7..495cc3ad 100644 --- a/zshrc +++ b/zshrc @@ -520,7 +520,7 @@ gc(){ if [[ $# == 0 ]]; then local branch=$(git branch -a --color=always |\ fzf --reverse --ansi --tac |\ - sed -E 's/^\*?[ \t]*//') + sed -E -e 's/^\*?[ \t]*//' -e 's@^remotes/[a-z]+/@@') [[ -n "$branch" ]] && git checkout "$branch" || true else git checkout "$@"