How do I find out what Git thinks the top-level working directory is?

imz -- Ivan Zakharyaschev picture imz -- Ivan Zakharyaschev · Jul 19, 2011 · Viewed 14.4k times · Source

Possible Duplicate:
Is there a way to get to the git root directory in one command?

Sometimes, I'm confused with git thinking that I'm inside a Git working dir, but it's not obvious to me what the top-level working directory (containing .git/) is. (Probably, that repo was created by a mistake.)

So, how do I find out the top-level Git repo directory if I'm somewhere inside the subdirectories? How do I ask git to print what it thinks the current top-level working directory is?

Answer

Graham Borland picture Graham Borland · Jul 19, 2011

Try this:

git rev-parse --show-toplevel