Since the git
command can be run from any subdirectory of the repo, or even from outside the directory hierarchy of the repo, I'm looking for a git
command that'll show me the location of the repo. Essentially, parent directory of the repo's .git/
directory.
For example, if I have a directory structure as follows, I want the output of the command to be /Users/gurjeet/dev/project_repo/
, for all the commands shown after the sample directory tree.
/Users/gurjeet/
├── some_directory/
└── dev/
└── project_repo/
├── .git/
└── src/
$ cd /Users/gurjeet/dev/project_repo
$ git --where-is-.git
$ cd /Users/gurjeet/dev/project_repo/src
$ git --where-is-.git
$ cd /Users/gurjeet/dev/
$ export GIT_DIR='/Users/gurjeet/dev/project_repo/src'
$ git --where-is-.git
$ cd /Users/gurjeet/dev/
$ export GIT_DIR='/Users/gurjeet/dev/project_repo/src'
$ git --where-is-.git
$ cd /tmp
$ export GIT_DIR='/Users/gurjeet/dev/project_repo/src'
$ git --where-is-.git