On Mon, Jun 19, 2017 at 08:46:45AM +0000, Patrick Lehmann wrote: > for Branch in $(git branch --list | grep "^ " | sed -e "s/ //" ); do > if [[ "$(git rev-parse "$Branch")" == $REF ]]; then > echo -e " \e[36mCheckout $Branch...\e[0m" > git checkout $Branch > FOUND=1 > break > fi > done I see Lars pointed you at for-each-ref, which is the preferred way for scripts to enumerate branches. But you can also use --points-at to skip the inner part of your loop entirely, like: git for-each-ref --points-at=HEAD --format='%(refname:short)' refs/heads That should run much faster, as it only has to spawn one process rather than one for each branch (it will print all of them, of course. You can pipe through head -n 1 to get the first, and check out --sort if you want to prioritize by recency or similar). -Peff