DJ_Stuffy_K
DJ_Stuffy_K

Reputation: 635

find active git branch of all 1st level subdirectories under a directory

Updated question based on comments:
Project P, is made up of submodules/mini-projects A, B,C,D,E.

Please note that A,B,C,D,E are directories which house their own projects, ex A: Web, B: Analytics C: Devops D:does_somethings E : Extra_features and so on. in other words each of A-E is its own repository.

A can have b1,b2,b3 branches which were created or checkeout by user1.
B can have x1,x2,x3 branches,, again by user1. and so on.
soEach subfolder A,B,C,D,E can have multiple unmerged/merged branches.

My question is , is there a command that will automatically tell me what branch is active on which repository (only A,B,C,D,E i.e first level only) present under P.

right now I'm cd'ing into each subfolder and then typing ' git branch'.
so if I have 10 subfolders, I have to cd into them 10 times and do git branch another 10 times.

I checked this: https://stackoverflow.com/a/2421063/4590025

git log --graph --pretty=oneline --abbrev-commit

but that is not what I'm looking for.

I am looking for something like a bird's eye view.

Upvotes: 2

Views: 1751

Answers (2)

torek
torek

Reputation: 487883

Git only works on one repository at a time.

A repository consists of object and reference databases and additional files as described in the documentation. A normal (non-bare) repository has one single work-tree, in which you do your work.

A work-tree can contain subdirectories, but these are just directories within the work-tree.

A work-tree can also contain, as sub-directories, submodules. These are Git repositories in their own right but are referenced by the containing superproject (the higher level Git repository). If you are working with submodules, there are Git commands for dealing with each submodule (e.g., git submodule foreach). Essentially, these run sub-commands inside the sub-repositories. See the git submodule documentation for details. This just automates what I'm about to suggest in the next paragraph. If you are using git submodule foreach itself, you still have to write the command.

Otherwise, e.g., you have a top level directory that contains N sub-directories each of which is an independent repository, you must run N separate git commands within each sub-directory to inspect the independent repositories. There is no Git command to do that. It's pretty trivial to write a shell command (with a loop) that does it, though:

for i in */; do \
     (cd $i && echo -n "${i}: " && git rev-parse --abbrev-ref HEAD); \
done

(this assumes a BSD or Linux compatible echo).

Upvotes: 14

Jacek
Jacek

Reputation: 874

Let's consider subfolder as a feature one developer is working on.

Locating a piece of work is easier when team follows the strategy of descriptive branch naming.

Example: Branch name "P/A/b1" tells you that there is work in progress in P/A/b1 location.

Upvotes: 0

Related Questions