6

I have to access some files stored in a Git repository, but I don't see where they are stored inside the repository folder.

Is there a special way to access the various files pushed from the clients?

CharlesB
  • 86,532
  • 28
  • 194
  • 218
jpmonette
  • 926
  • 1
  • 15
  • 30

3 Answers3

6

If this is a bare repo, you wouldn't find those file in the repo.git folder.
See "all about "bare" repos": a bare repo has no working tree, and is used for pushing to it (since there is no working tree to keep in sync with an updated branch)

The easiest way to see those file is to clone said bare repo:

git clone /path/to/repo.git /path/to/repo
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • how do you get it updated every time you commit if you only clone it.? – zero8 Mar 13 '19 at 10:13
  • @zer If you make new commits, you can push back to that bare repo, which will update it. – VonC Mar 13 '19 at 10:33
  • I get the idea now thanks i've added a hook post-recieve to pull the latest commit. coming from using svn i am setting up git server now. thanks ( = @vonC – zero8 Mar 13 '19 at 11:43
  • @zero8 Well done! I used a similar solution in https://stackoverflow.com/a/48577475/6309 – VonC Mar 13 '19 at 11:47
5

I know only a hack-ish way to see the list of files in a bare repository without cloning:

GIT_DIR=/path/to/bare.git git log --pretty=format: --name-only --diff-filter=A

You most probably want to sort that output and exclude blank lines:

GIT_DIR=/path/to/bare.git git log --pretty=format: --name-only --diff-filter=A | sort | grep .

Viewing the content of a file is pretty clean though:

GIT_DIR=/path/to/bare.git git show HEAD:path/to/file

If you want to get specific files out of the bare repository but not entire repository, you could redirect the output of git show to a file.

Btw, GIT_DIR=... git cmd is equivalent to git --git-dir=... cmd

janos
  • 120,954
  • 29
  • 226
  • 236
1

Git repositories are often stored on the server as a bare repository. This is effectively the contents of the normal .git directory, and does not include an extracted working copy.

To access files stored in such a repository I recommend cloning the repository. If you want to do this from the server you can do something like git clone file /path/to/bare/repository /path/to/clone.

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257