1

We have two Git repos on a remote git server in this format:

/git/repo1
/git/repo2

In /git/repo1, I see these files & directories:

branches  config  description  HEAD  hooks  info  objects  refs

In /git/repo2, I see this directory:

.git

and within .git, I see

branches  config  description  HEAD  hooks  info  logs  objects  refs

Both repos appear to work fine. However ...

I am trying to figure out how this happened and if there is a problem with setup just waiting to jump out. Which one is "right" or does it not matter? If one is preferred (I think it might be repo1's format), how do I make /git/repo2 to look like /git/repo1 (or vice versa)?

halfer
  • 19,824
  • 17
  • 99
  • 186
KM.
  • 1,382
  • 1
  • 19
  • 34

3 Answers3

2

looks like one is bare and the other isn't. If it's on a server, you want a bare repo.

Adam Dymitruk
  • 124,556
  • 26
  • 146
  • 141
2

repo1 Was probably created with git init --bare or cloned with git clone <uri> --bare

repo2 Was created or cloned without the --bare keyword.

If you don't expect anyone to be working on a checkout branch and that the repository is used only for pushing and fetching from then the bare format is all that is needed and is recommended.

The non-bare format is simply a directory for the checked out snapshot of code and the git repo is actually stored in the .git directory which is the same as a bare repository. This is usually the case when someone is actually working on data associated with a git repository.

James
  • 1,754
  • 14
  • 22
  • Is there a way to see how the repo was created? Similar to a `SHOW CREATE TABLE;` in MySQL? I didn't create repo1, but created repo2 using (if I recall correctly) `git init`, `git remote add origin` followed by a `git push uid@host:/git/repo2` – KM. Feb 10 '12 at 21:17
  • 1
    @KM It is unclear to me in which repos you did your `git remote` and `git push` commands.AFAIK there isn't a direct and definitive way to know how a repository was created. There are context clues, like the what is shown in the configuration file and if there are any remotes. In repo1 you can do `git remote show` and if there is an `origin` remote that MIGHT mean it was cloned vs. initialized. Your best way to know how it was created is to ask the person that created it if they are still around and can remember. – James Feb 10 '12 at 21:27
  • 1
    Or document such changes, right ... ? (-: Thanks for the answer! – KM. Feb 10 '12 at 21:40
  • @KM Yep! I'm a big fans of including such information in my initial commit if I'm the creator of the original repository. When I use github I'll often create wiki pages that are associated with the project to store all my documentation about the project. Some information about the project, like how it was created and what remotes are important isn't appropriate to share with the world, or have it edited, and is why I don't simply add something like a git_readme.txt to the repo itself. – James Feb 10 '12 at 22:37
2

Repo1 is a bare repository and the other is not. Bare repositories are usually used only to be remotely connected to. Non-bare repositories are the kind developers do their work in.

This post details how to convert to a bare repository.

Community
  • 1
  • 1
Karl Bielefeldt
  • 47,314
  • 10
  • 60
  • 94
  • 1
    So, essentially, move all the contents of `/git/repo2/.git` directory in to `/git/repo2`, remove the `.git` directory, and set the `core.bare` to `true`? – KM. Feb 10 '12 at 21:13