1

Right now I can see my GitHub projects overview looks like this:

Project A - api (visual studio)
Project A - app (visual code)

Project B - api (visual studio)
Project B - app (visual code)

Project C - api (visual studio)
Project C - app (visual code)

The list is long and I dont like this way at all and instead I want to achieve something like this:

Project A
   - api
   - app

Project B
   - api
   - app

Project C
   - api
   - app

Basically I want a main folder with 2 or more subfolders with their own repo url. Right now I can see that only the root folder has the repo url and not subs.

Anybody please guide me how to achieve this?

Danny Web
  • 217
  • 5
  • 17

1 Answers1

0

While GitHub itself doesn't directly support creating subfolders with separate repository URLs, you can achieve a similar organization using a combination of GitHub repositories and submodules.

Disclaimer before you go further down: Using submodules adds some complexity so please make sure you understand how they work before making any major changes to your repo structures. https://github.blog/2016-02-01-working-with-submodules/

Example repository that uses a submodules: https://github.com/githubtraining/example-dependency

I will try to go through the steps you want to take to achieve this:

  1. Create separate repositories for each component (api, app, and one main one, ProjectA for example ). Each of these repositories will have its own URL.

  2. Clone each repository to your local machine. Arrange them in the desired directory:

    Project A

    ├── api

    │ └── (contents of api repository)

    └── app

       └── (contents of app repository)
    
  3. Add the submodules to the "main" repository. If your folder structure looks like the above possible steps might look like this:

cd ProjectA

Add the api repository as a submodule

git submodule add <api-repo-url> api

Add the app repository as a submodule

git submodule add <app-repo-url> app

Commit the changes to the main repository (ProjectA)

git commit -m "Added submodules for api and app"

  • 1
    If I approach in this way the overview on github repos will still loook like sphagetti as everything will be on the flat structure? – Danny Web Aug 25 '23 at 09:54
  • If I understand your question correctly. I don't think your repos will look like spaghetti. Since you will be able to use the main repo for files which you want to be "top level" (Like README.md for the whole Project for example). The App and Api repos will be separated with different commit histories, branches, etc. And in you can still pull updates to both the Api and App from the main repo. Check out this https://stackoverflow.com/questions/4611512/is-there-a-way-to-make-git-pull-automatically-update-submodules for correctly pulling and updating submodules. – Tsvetislav Todorov Aug 25 '23 at 10:36