Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (29.3k points)

Mercurial has a way of printing the root directory (that contains .hg) via

hg root

Is there something equivalent in git to get the directory that contains the .git directory?

1 Answer

0 votes
by (50.2k points)

Yes, there is a way in git to get the directory that contains the .git directory use the following command 

git rev-parse --show-toplevel

Note: In a submodule, this will display the root directory of the submodule and not the parent repository.

If you are in a submodule folder, with Git >=2.13, use:

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

For older versions, git refer: https://git-scm.com/docs/git-rev-parse#Documentation/git-rev-parse.txt---show-superproject-working-tree

Browse Categories

...