Working with submodules in github

Mritunjay KumarMritunjay Kumar
1 min read

Make sub repository inside main repository.

Assume you have a project that contains two folders, server and client, to manage the repository called submodules.

To set up Git submodules with separate repositories for the client and server, and a main repository to tie them together.

Follow these steps:

  • Create the client and server repositories

  • Create two separate repositories on your Git: one for the client and one for the server.

  • Upload the client code to the client repository.

  • Upload the server code to the server repository.

  • Clone both repositories to your local machine.

  • Next, create the main repository and clone it to your local machine.

  • Open Git Bash and navigate to the directory of the main repository.

  • Add the client repository as a submodule:

      git submodule add <client_repo_url> client
    

    Add the server repository as a submodule

      git submodule add <server_repo_url> server
    

After adding the submodules, initialize and update them:

git submodule init
git submodule update

Commit and push changes to the main repository

git add .
git commit -m "Add client and server submodules"
git push origin main

Now it's done.

0
Subscribe to my newsletter

Read articles from Mritunjay Kumar directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Mritunjay Kumar
Mritunjay Kumar