git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: Patrick Lehmann <Patrick.Lehmann@plc2.de>
Cc: Git Mailinglist <git@vger.kernel.org>
Subject: Re: Restoring detached HEADs after Git operations
Date: Mon, 19 Jun 2017 13:01:24 -0400	[thread overview]
Message-ID: <20170619170124.6oj6stoojds4srci@sigill.intra.peff.net> (raw)
In-Reply-To: <0092CDD27C5F9D418B0F3E9B5D05BE08010287DF@SBS2011.opfingen.plc2.de>

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

  parent reply	other threads:[~2017-06-19 17:01 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-19  8:46 Restoring detached HEADs after Git operations Patrick Lehmann
2017-06-19  9:30 ` Lars Schneider
2017-06-19  9:52   ` AW: " Patrick Lehmann
2017-06-19 16:37     ` Stefan Beller
2017-06-19 17:34       ` AW: " Patrick Lehmann
2017-06-19 17:47         ` Stefan Beller
2017-06-19 18:09           ` AW: " Patrick Lehmann
2017-06-19 19:21             ` Stefan Beller
2017-06-19 20:13               ` AW: " Patrick Lehmann
2017-06-19 17:55       ` Junio C Hamano
2017-06-19 19:11         ` Stefan Beller
2017-06-19 16:31 ` Stefan Beller
2017-06-19 17:01 ` Jeff King [this message]
2017-06-19 17:56 ` Ævar Arnfjörð Bjarmason

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170619170124.6oj6stoojds4srci@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=Patrick.Lehmann@plc2.de \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).