2

I ended up creating several git clones of various repositories over time, and in some of the clones, I created more than one branch. I want to now find the clone which has a specific branch.

I looked through StackOverflow questions and came across the following post Git Status Across Multiple Repositories on a Mac. Using this as reference, I decided to write my own shell script to do list all clones and the branches in each clone. However, by greping in the .git directory, I could not find any place where this information is available. The HEAD file only has information about the currently checked out branch.

I can certainly write a script to process the output of git branch in each clone's working directory. However, before I start on that, I would like to know if there is an easier way of obtaining this information.

Community
  • 1
  • 1
Masked Man
  • 1
  • 7
  • 40
  • 80

1 Answers1

1

.git/refs/heads should contain all of your local branches.

I am curious -- why isn't using git branch in a shell script sufficient?

Mark Leighton Fisher
  • 5,609
  • 2
  • 18
  • 29
  • Thanks. A shell script would work more or less like following: `find` all the `.git` directories, then `cd` to their `dirname` portion, and then run `git branch` there. But with your answer, it can be simpler (and likely faster, since it only involves shell commands and no git commands). My analysis could be wrong though. – Masked Man Dec 15 '12 at 16:54
  • This is not so simple. [Refs can be packed.](http://www.kernel.org/pub/software/scm/git/docs/git-pack-refs.html) – Michał Politowski Dec 15 '12 at 20:41