Search code examples
gitgithubwebherokugit-submodules

Separate FE and BE on Heroku but single repo on Github?


Setup

I have a web project whose front and backends are hosted on Heroku separately. It is stored in my machine as so:

project root
├── backend
│   ├──── stuff
│   └──── .git
├── frontend
│   ├──── stuff
│   └──── .git
├── project-wide config files
├── scripts
└── README.md

Problem

As you know, deployment to Heroku requires the backend and frontend folders to have their own git folders... but on Github, I want to unify this whole project into one repo, like it is on my machine.

What are the best practices to this issue? Is git submodules a good solution?

I am also entertaining the idea of docker-composing this whole project.


Solution

  • The usual approach is to define a third Git repository, one which will reference the other two (front and back).

    That reference would be registered as submodule, allowing any one cloning the parent repository to get the latest of said sub-repositories:

    git clone --recurse-submodules --remote-submodules 
    

    Don't forget, when you add those submodule, to specify a branch in order for the parent repository to get the latest of those submodules.

    Using GitHub CLI gh:

    git init myProject
    cd myProject
    git submodule add -b main [/url/repo/front]
    git submodule add -b main [/url/repo/back]
    git commit -m "Add front and back repositories"
    gh repo create myProject --source=.
    git push -u origin main