2

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.

DJ_Stuffy_K
  • 615
  • 2
  • 11
  • 29
  • 1
    Why are you keeping each folder in a branch? – evolutionxbox Mar 14 '18 at 15:28
  • 10 people are working on project P. each folder is a different sub project. So everybody works on their own branch. for unmerged MR's I checkout another's branch and work on it and resubmit a MR. So I would like to get a bird's eye view of which branches A,B,C,D and E are on my laptop. – DJ_Stuffy_K Mar 14 '18 at 15:34
  • You can't cd into directory which exist only in another branch than the one that is checked out. Please specify your question better – Jacek Mar 14 '18 at 15:34
  • Are we talking about one repository? You can't checkout branch A in one directory and branch B in another directory at the same time. When you checkout a branch, it will switch the entire repository to that branch, there is no other way. – anothernode Mar 14 '18 at 15:36
  • P is the parent directory. @anothernode , A to E are dependent on one another. Are you saying it not possible to be one a different branch on A, and at the same time be on another branch on B and so on? – DJ_Stuffy_K Mar 14 '18 at 15:42
  • @Jacek just updated the question to make my question as clear as possible – DJ_Stuffy_K Mar 14 '18 at 15:42
  • What are A and B? Directories? If A and B are directories, then, yes, that is what I'm saying. – anothernode Mar 14 '18 at 15:45
  • Repositories have branches and a given directory D can exist on one branch and not exist on another. But it doesn't make sense to say that one directory "is on this branch" and another directory "is on another branch" in git. – anothernode Mar 14 '18 at 15:48
  • by subfolder, I was referring to repositories only. sorry about the wrong terminology. @anothernode – DJ_Stuffy_K Mar 14 '18 at 15:54
  • 1
    So are you talking about submodules? – evolutionxbox Mar 14 '18 at 15:57
  • 1
    I see, that is a whole different story then. I'd recommend making very clear in your question that you are talking about subprojects residing in their own repositories, because that will affect the usefulness of potential answers quite a bit. – anothernode Mar 14 '18 at 15:57
  • @evolutionxbox yes submodules, if that is what they are called. anothernode. ok thanks let me try to rephrase the question again. I'm not sure if it will allow me to change it so many times or not. – DJ_Stuffy_K Mar 14 '18 at 15:59
  • 1
    I'm not sure, but I think you can edit your own question as much as you like. It would probably also help, if you could determine if you are actually using submodules as @evolutionxbox suggests, or not. You can read about them here: https://git-scm.com/book/en/v2/Git-Tools-Submodules – anothernode Mar 14 '18 at 16:02

2 Answers2

11

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).

torek
  • 448,244
  • 59
  • 642
  • 775
0

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.

Jacek
  • 829
  • 12
  • 31
  • sorry if my terminology was confusing. P is the complete project. It has folder A,B,C,D and E, and each of them is a complete mini project, in other words , each is an individual repository to which people can push,pull and create mr's. So if each repository is using a different branch, then how to get a bird's eye view of which branch is active on each of the repos A,B,C,D,E? – DJ_Stuffy_K Mar 14 '18 at 15:57