Skip to content

Commit

Permalink
Check out local branches that track remote
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
gabebw committed Aug 12, 2017
1 parent 2fc9bf2 commit 18c56bf
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion zshrc
Expand Up @@ -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 "$@"
Expand Down

0 comments on commit 18c56bf

Please sign in to comment.