Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple projects in one git repo?

Tags:

I'm an SVN user at the moment and looking at moving my projects to git.

I use one SVN repository to hold all the projects I create. My structure is something like this:

/     /group1         /subgroup1             /project1                 /branches                     ...                 /tags                     ...                 /trunk                     ...             /project2                 ...         /subgroup2             /project3                 ...             /project4                 ...     /group2         /subgroup3             ...         /subgroup4             ...     /lib         /lib1         /lib2         /lib3 

As you can see I keep my projects in groups and /lib contains libraries shared between projects.

I chose this sort structure because:

  1. Similar repo structure was used in the company where I learned to use SVN.
  2. Allows me to have an svnserve running as a service/daemon on my machine with all projects hosted on it (I don't like filepath approach).

Now... to the point. I was wondering:

How this sort of workflow would work if I were to move to git?

Specifically:

  1. Would it be simple to migrate the repo tree to git?
  2. Assuming each project requires separate repo*, how would I be able to serve them all (ideally grouped in similar fashion) via svnserve git equivalent.

*) I read about git and I understand that is the case, but I wanted to double check with experienced people.

like image 299
Michal M Avatar asked Aug 11 '11 22:08

Michal M


People also ask

Can a Git repo have multiple projects?

Yes. You can put multiple projects in one Git repository but they would need to be on different branches within that repo.

Should I have a repository for each project?

If your projects are independent, it's fine to keep them in separate repositories. If they share components, then put them together. Very good reasoning, this should be the top answer in my opinion.

How would you go on about pushing the same file to two different projects using Git?

Doing git remote -v should reveal the current URLs for each remote. Now, if you want to push to two or more repositories using a single command, you may create a new remote named all (as suggested by @Adam Nelson in comments), or keep using the origin , though the latter name is less descriptive for this purpose.


1 Answers

In Git, it is better to have each project in its own repo, and the libraries in another repo if needed and used as submodules ( equivalent of svn externals) in each project.

This is because in Git, a repo is a much more lightweight concept than SVN and also, more importantly, there is no ability to clone individual folders ( not to be confused with sparse checkout) within a repo separately like you are able to checkout and work on individual folders in SVN. So if you had all projects in a single repo, you will have to clone them all.

Serving Git repos, using smart-http, git daemon and ssh is pretty straightforward. There is also Gitolite for managing multiple repos ( including authorization and authentication). Read the linked chapter on ProGit on serving Git repos- http://progit.org/book/ch4-2.html

Coming to your grouping, you can put the repos in folders as per your grouping structure, and serve using, say smart http method, whereby the repo urls will look like the urls that you would have used with SVN, will all projects seeming to be under the grouping etc.

like image 153
manojlds Avatar answered Sep 20 '22 22:09

manojlds