Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple repositories in one directory

Tags:

git

svn

This is a question that seems to come up semi-frequently, but sadly I've not found an answer that I can fully apply to my situation yet, so I figured I'd ask my own question. This is my first question on SO, so be nice. :P

The "problem": Our company develops multiple PHP applications, however one of those applications is a "master" of sorts. All of our other applications is installed inside this "master application", and requires the master application to work.

We use version-control to manage these applications, of course.

While many of the files in our addon applications are in subdirectories, not all of them are. This means that we cannot use subdirectory importing (svn externals, git submodules, etc.). For instance, within the root folder there are several folders (admin, public, kernel and so on) and the addon applications have files within one or more of these folders - they are not independently self-contained within the directory structure of the master application.

We currently use SVN and recently found ourselves considering git due to some of the features available we feel could be useful to us. One thing I'm not clear on with git, however, is if there is truly a way to "merge" (not in the version control sense) these repositories into a single directory locally when developers are working on the code. I have not found a way to do this with SVN either.

In an ideal world, we would have one repository for our "master" application with a structure like so:

  • /
  • --file1
  • --file2
  • --/admin
  • ----file1
  • ----file2
  • --/public
  • ----file1

Our addon application would have a structure like so (remember, we have multiple addon applications):

  • /
  • --filex
  • --/admin
  • ----/myapp
  • ------file1
  • ------file2
  • --/public
  • ----filex

We have experimented with the following approaches, each with its own caveats:

  1. All applications in a single repository. This is less than ideal as it becomes a nightmare managing versions for each application effectively (especially in SVN). Branching and tagging take along files from unrelated and separate applications.
  2. All applications in a separate repository. This is also not ideal (well, it is from a management/organization perspective) because you cannot export two separate repositories to a single folder, so you always work with a checkout of one repository and an export of others. If you are working on application X and there are changes in our master application, you need to manually do a new export of that master application and copy the files over to the application X repository you are working on to have the latest framework code.

Is there any way with git or SVN (or any other version control system for that matter) to allow more than one repository within a single directory without using subdirectories? SVN externals is nearly perfect, but has the requirement that all files in the external repository be in a separate subfolder, which as described above does not work for us. I gather git has equivalent capabilities, but again cannot allow more than one repository in a single folder, leaving us with the same issue.

Related questions: Multiple repositories in one directory (same level) - is it possible? - this is very close to what I am asking I think, but I did not see any solution that I felt could be applied to our situation.

like image 566
bfarber Avatar asked Dec 30 '11 18:12

bfarber


2 Answers

I have never attempted to do something like this in a production environment, but you could certainly do:

$ git init
$ mv .git .git1
$ git init
$ mv .git .git2
$ export GIT_DIR=.git1
# do work in first repo
$ export GIT_DIR=.git2
# do work in second repo
like image 70
William Pursell Avatar answered Nov 10 '22 01:11

William Pursell


git allows you to specify work-directory and git-directory on the top level git command:

git status

can be altered to use a different .git folder with

git --git-dir=some/other/path/to/a/different/.git/folder status

Likewise, you can specify a different working folder:

git --work-tree=some/other/path status

You can also combine the 2.

If you have to have this workflow all the time, you can override and wrap the git command to always point to a specific .git dir or work dir. An example is "git achievements" which intercepts git commands and gives you rewards for getting better with git and then calls the actual git command: https://github.com/icefox/git-achievements

Looks like a fun problem to solve.

I would also look at just having a branch per application and continually rebase those branches on top of any work that is done to the core app. This would actually be my first choice.

like image 3
Adam Dymitruk Avatar answered Nov 09 '22 23:11

Adam Dymitruk