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

"git add" and absolute paths

From
Wincent Colaiuta <win@wincent.com>
Date
Jan 28, 2008, 12:32 UTC
Message-ID
<916BAC14-A5E4-4666-A29E-2CDF114DCD87@wincent.com>

I was somewhat surprised the other day to see that you can't pass absolute paths to "git add":

$ cd /tmp $ mkdir foo $ cd foo $ git init Initialized empty Git repository in .git/cuzco:foo $ echo "content" > file $ git add /tmp/foo/file fatal: unable to add /tmp/foo/file to index $ git add file

I understand that you can't add arbitrary paths outside of your worktree, but if the absolute path specifies something _inside_ your worktree then it seems that this is either a bug or a "usability shortcoming" if you prefer to avoid the term "bug".

I also understand that providing a relative path is by far the most common operation, but there are real use cases where it's easier to pass an absolute path. For example: you're working at the console inside the work tree but you also have a GUI file browser open alongside. Sometimes it is simpler to drag-and-drop the file from the GUI to the console window (thus inserting the absolute path to the file) rather than typing out the relative path, even with autocompletion.

Out of curiosity I went back and looked at the last version of Git before "add" became a built-in (1.3.3). It also barfs for absolute paths:

$ git add file Ignoring path /tmp/foo/file

So I suspect it's always been this way. Do people agree that this issue is worth addressing?

Cheers, Wincent

Next: Johannes Schindelin
Message 1 of 4 in “"git add" and absolute paths”
  1. Wincent ColaiutaJan 28, 2008
  2. Johannes SchindelinJan 28, 2008
  3. Jakub NarebskiJan 28, 2008
  4. Jeff KingJan 28, 2008

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.