Single Github repository for two local repos for a fullstack project

33 Views Asked by At

I was working on a fullstack MEAN project and I decided to create separate local repos for client and server. The alternative was to have a single repository with separate branches for client and server but I picked the Separate repository approach so that I didn't have to do a merge every time I changed something on the backend branch, for having the latest backend code in the working directory when I'm working on the frontend. I now realize that I could've used the git worktree command maybe, but right now I have separate repos. My folder structure is like this:

--MyProject
    --client
        --.git
    --server
        --.git

I now want to add the project to GitHub but I don't want to create two separate repositories there. I want a single repository which when cloned will pull the entire project, both frontend and backend. But the repos in client and server should be isolated from each other, that is any commit in one repo should be independent of the other and their histories should be separate.

I read about a git feature called submodules but I am unsure if that is what I'm looking for. In every tutorial it's mentioned that submodules are generally used when we want to use some third party repo in our own version controlled project. Also it seems overly complex for this simple task of placing the two repos in a single container on GitHub.

1

There are 1 best solutions below

1
Hithesh Jay On

It seems you're making things complex. You don't need submodules here,

First you can initialize a new Git repository locally in your --MyProject folder.

cd MyProject
git init

Then do,

git add client
git add server

Then commit and push to the GitHub (make sure to create a GitHub repo first)

This way, your GitHub repository will contain both the client and server directories. They will be isolated from each other within the repository, and users cloning the repository will get both directories but can work on them independently.