git/list[1] front-page[2] threads[3] people[4] search[5] about
 

`git rev-parse --git-dir` relative to current working directory?

From
Elliott Cable <me@ell.io>
Date
Mar 29, 2016, 10:32 UTC
Message-ID
<CAPZ477NfQ7pCiHQ3V42kZ1Cic5UPP03TCFPvABR_ugSZYEn4xg@mail.gmail.com>

So, `git help rev-parse` [mentions the following][rev-parse], as of 2.8.0:

    --git-dir
       Show $GIT_DIR if defined. Otherwise show the path to the .git
       directory. The path shown, when relative, is relative to the
       current working directory.

However, when inside a symlinked repository, this doesn't function as advertised:

    $ ln -s a-symlink a-git-repo
    $ cd a-symlink/.git/hooks
    $ git rev-parse --git-dir
    /Users/ec/Documents/a-git-repo/.git

From my reading of that snippet of documentation (“The path shown ... is relative to the CWD”), I'd expect to receive `..`, not `/absolute/path/to/a-git-repo/.git`.

Is the documentation incorrect, or is this a bug? (I'm hoping the latter: I'm trying to write git-scripting that is sensitive to symlinks, i.e. retains the user's CWD without unintentionally resolving symlinks in their path during operation; and it'd be ideal if this were handled as documented, saving me manual effort checking symlinks.)

⁓ ELLIOTTCABLE — fly safe.
  http://ell.io/tt
   [rev-parse]:
<https://git-scm.com/docs/git-rev-parse/2.8.0#_options_for_files>
      "git rev-parse documentation @2.8.0"
Next: John Keeping
Message 1 of 2 in “`git rev-parse --git-dir` relative to current working directory?”
  1. Elliott CableMar 29, 2016
  2. John KeepingMar 29, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.