git: get current working dir

4

1

How I can get current working dir from console using git?

something like: if I'm in: ~/projects/someproject/somesubfolder/, the console command should say /home/va1en0k/someproject/ (if there is a .git/ folder in this directory or something like this)

or if GIT_WORKING_DIR is set, it should return it. or whatever Git uses to determine it

valya

Posted 2011-04-10T18:52:46.157

Reputation: 748

Answers

10

Try this:

echo $( cd $(git rev-parse --show-cdup); pwd)

George V. Reilly

Posted 2011-04-10T18:52:46.157

Reputation: 730

10I looked at git-rev-parse(1). It seems like "git rev-parse --show-toplevel" will suffice. Thank you! :-) – valya – 2011-04-10T19:03:57.503

12

Simple: git rev-parse --show-toplevel

sorin

Posted 2011-04-10T18:52:46.157

Reputation: 9 439

1How is this different from 'valya Apr 10 '11 at 19:03' comment below the accepted answer, we can all miss things. – mic84 – 2018-08-23T10:39:22.070

2A comment is not an answer, it cannot be accepted. – sorin – 2018-08-26T07:47:07.547

--show-toplevel will be an absolute path apparently, and --show-cdup will be relative to cwd. – Alexander Bird – 2019-10-29T17:12:47.987