0

Is there a way to get the git root directory in one command? shows how to get the root of the current git tree, but if I have a super project (say the directory is: /a/b/mySuper) and submodule directories sub1, sub2 and sub3 underneath, How to get the root directory of the super project ("/a/b/mySuper" in this case) when my current $PWD being '/a/b/mySuper/sub2/dir1', if I run git rev-parse --show-toplevel from '/a/b/mySuper/sub2/dir1', it prints '/a/b/mySuper/sub2', instead I am looking for a command to print the top-super's directory '/a/b/mySuper'

rodee
  • 3,233
  • 5
  • 34
  • 70
  • 3
    A submodule (directory) may not even know it is a submodule. Furthermore, it may have several parent directories, if it's e.g. symlinked etc. – rubenvb Aug 21 '18 at 14:21
  • You should treat them as independent repositories or not use sub modules. – Liam Aug 21 '18 at 14:26

1 Answers1

2
git rev-parse --show-superproject-working-tree

I think this popped up in git 2.13.0. Note that this only shows the immediate superproject and that nothing is printed to stdout when not called from within a submodule.

ov2k
  • 295
  • 1
  • 10