Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
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

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.1k users

Browse Categories

...