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

Re: I don't want the .git directory next to my code.

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Jan 17, 2008, 17:36 UTC
Message-ID
<alpine.LFD.1.00.0801170849070.14959@woody.linux-foundation.org>
In-Reply-To
<20080117151725.GC2816@coredump.intra.peff.net>
On Thu, 17 Jan 2008, Jeff King wrote:
Show 5 quoted lines
> 
> You don't seem happy with any of those. But the fact remains that the
> git repo has to be stored _somewhere_, and when you run git, there needs
> to be some mapping telling it which git repo matches your working
> directory. So how _do_ you want to specify that mapping? 
Ok, here's the ugliest idea *ever*:

We could actually use POSIX extended attributes (or whatever system-specific version of it a particular filesystem supports) for people who *really* don't want to pollute their file structure.

I know, I know, it's horrible. It's one of those things that would actually be reqlly convenient (and probably even pretty easy to implement), but is also going to be *really* subtle when it breaks.

But I bet some people would like it. I personally tend to hate extended attributes (they tend to have serious problems with anything that moves things around or backs them up - especially across filesystem boundaries), but there is no question that they can't be convenient to hide information.

Anyway, here's a really stupid patch. It kind of works, but it has no way to turn this off.

On at least Linux, with this you can do something like
	.. start off with a git directory ..
	mv .git /external/git/location
	setfattr -n user.git-dir -v /external/git/location .

and now that "user.git-dir" thing acts as a kind of invisible "symlink" to the external git directory.

Not exactly heavily tested, and I don't know how portable the whole xattr thing is (ie I know OS X has file attributes, I just don't know if the interface is at all similar).

I don't like extended attributes myself, but this patch really is pretty simple and perhaps useful.

			Linus
---
 setup.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)
diff --git a/setup.c b/setup.c
index adede16..97865f4 100644
--- a/setup.c
+++ b/setup.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "dir.h"
+#include <attr/xattr.h>
 
 static int inside_git_dir = -1;
 static int inside_work_tree = -1;
@@ -302,6 +303,9 @@ const char *setup_git_directory_gently(int *nongit_ok)
 	 */
 	offset = len = strlen(cwd);
 	for (;;) {
+		int attr_len;
+		static char git_dir[PATH_MAX];
+
 		if (is_git_directory(DEFAULT_GIT_DIR_ENVIRONMENT))
 			break;
 		if (is_git_directory(".")) {
@@ -312,6 +316,14 @@ const char *setup_git_directory_gently(int *nongit_ok)
 			check_repository_format_gently(nongit_ok);
 			return NULL;
 		}
+		attr_len = getxattr(".", "user.git-dir", git_dir, sizeof(git_dir)-1);
+		if (attr_len > 0) {
+			git_dir[attr_len] = 0;
+			if (is_git_directory(git_dir)) {
+				setenv(GIT_DIR_ENVIRONMENT, git_dir, 1);
+				break;
+			}
+		}
 		chdir("..");
 		do {
 			if (!offset) {
Previous: Jeff KingNext: Johannes Schindelin
Message 17 of 65 in “I don't want the .git directory next to my code.”
  1. MikeJan 16, 2008
  2. Randal L. SchwartzJan 16, 2008
  3. MikeJan 16, 2008
  4. David SymondsJan 16, 2008
  5. MikeJan 16, 2008
  6. SeanJan 16, 2008
  7. MikeJan 16, 2008
  8. Neil MacnealeJan 16, 2008
  9. MikeJan 16, 2008
  10. Johannes SchindelinJan 16, 2008
  11. Linus TorvaldsJan 16, 2008
  12. Linus TorvaldsJan 16, 2008
  13. MikeJan 17, 2008
  14. Kris ShannonJan 17, 2008
  15. Wincent ColaiutaJan 17, 2008
  16. Jeff KingJan 17, 2008
  17. Linus TorvaldsJan 17, 2008
  18. Johannes SchindelinJan 17, 2008
  19. Linus TorvaldsJan 17, 2008
  20. Johannes SchindelinJan 17, 2008
  21. MikeJan 17, 2008
  22. Johannes SchindelinJan 17, 2008
  23. MikeJan 17, 2008
  24. Johannes SchindelinJan 17, 2008
  25. MikeJan 17, 2008
  26. Johannes SchindelinJan 17, 2008
  27. MikeJan 17, 2008
  28. Johannes SchindelinJan 17, 2008
  29. David SymondsJan 18, 2008
  30. Russ DillJan 22, 2008
  31. Martin LanghoffJan 17, 2008
  32. Andreas EricssonJan 18, 2008
  33. Junio C HamanoJan 16, 2008
  34. Ping YinJan 17, 2008
  35. Linus TorvaldsJan 17, 2008
  36. Dan McGeeJan 16, 2008
  37. MikeJan 16, 2008
  38. Mike KrierJan 16, 2008
  39. MikeJan 16, 2008
  40. Nguyen Thai Ngoc DuyJan 16, 2008
  41. David SymondsJan 16, 2008
  42. MikeJan 16, 2008
  43. Daniel BarkalowJan 16, 2008
  44. Luke LuJan 16, 2008
  45. MikeJan 16, 2008
  46. Sam VilainJan 17, 2008
  47. Daniel BarkalowJan 16, 2008
  48. MikeJan 16, 2008
  49. Johannes SchindelinJan 16, 2008
  50. Bert WesargJan 16, 2008
  51. Wayne DavisonJan 16, 2008
  52. Matthieu MoyJan 16, 2008
  53. Johannes SchindelinJan 16, 2008
  54. Bill LearJan 16, 2008
  55. Matthieu MoyJan 16, 2008
  56. Johannes SchindelinJan 16, 2008
  57. Junio C HamanoJan 16, 2008
  58. Johannes SchindelinJan 16, 2008
  59. Matthieu MoyJan 16, 2008
  60. Johannes SchindelinJan 16, 2008
  61. Jakub NarebskiJan 16, 2008
  62. Brian DowningJan 17, 2008
  63. Randal L. SchwartzJan 17, 2008
  64. Martin LanghoffJan 17, 2008
  65. Randal L. SchwartzJan 17, 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.