Creating two projects in a single Git repository

Asked

Viewed 2,506 times

7

I am creating a project in Java web and want to create another project on Android. But I would like to create only one repository and within it own these two projects with their respective trees commits, as if they were separate components.

You can create something like this in Git?

  • you can separate projects into folders... but I don’t know if it’s the right way

2 answers

8


It’s not possible. Git has its advantages, but one of the drawbacks is just that. Git works with the repository as a whole. It’s actually more common when you need better organization and access control to have a separation of projects into parts and each to have its own repository.

Of course you can, even if not recommended, put both in the same repository, but it will be one thing from Git’s point of view. You can do this, but any attempt to manage as if they were separate things will bring more confusion.

Separate into two repositories and be happy. There’s no reason not to do this.

If you want to insist, has an OS solution. Don’t think it’s simple to handle it properly. I don’t know if you’ll have everything you want and especially if it makes up for the effort, especially when something goes wrong.

In your case, it seems to me that the projects are so distinct that it wouldn’t be worth even trying to put everything in one repository.

And of course if you want to treat it as one thing, it’s no secret.

1

I really don’t know the configuration that allows the inclusion of more than one project in the same repository, as you suggested.

But, an alternative would be for you to use a Git function subtree which allows the possibility of structuring different repositories in such a way that it passes the impression that it is all in one.

This git feature allows you to manage multiple repositories in such a way:

Repositorio
   |--- Reposotorio_1.0
   |    |--- index.html
   |    |--- README.md
   |    |
   |    |--- Repositorio_1.1
   |         |--- index.html
   |         |--- README.md
   |    
   |--- Reposotorio_2.0
   |    |--- index.html
   |    |--- README.md
   |  
   |--- README.md

The basic steps consist of:

  1. Create the republics that will be used
  2. Create Remotes for each of the repositories

    git remote add repositorio-1_0 https://github.com/usergit/Repositorio-1_0.git
    git remote add repositorio-1_0 https://github.com/usergit/Repositorio-2_0.git
    
  3. Add "child repositories" from the main repository

    git subtree add --prefix=Repositorio-1_0/ Repositorio-1_0 master
    git subtree add --prefix=Repositorio-2_0/ Repositorio-2_0 master
    

Obs.: In this template you should be aware of the repositories' update flow and can be updated from the main repository to the child repositories

Example with 'push'

    git push ---> No principal 
    git subtree add --prefix=Repositorio-1_0/ Repositorio-1_0 master
    git subtree add --prefix=Repositorio-2_0/ Repositorio-2_0 master

Below is a reference to an article that will bring more details:

Article by "ROBERTO ACHAR - Multiple repositories"

  • Hello, Luiz! Can you detail some things described in the link in your answer? This is important because this site may go off the air one day. In the OS, it is important that responses do not rely too much on external links to help users.

  • This is @Dherik, it really makes sense!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.