JIYIK CN >

Current Location:Home > Learning > OPERATING SYSTEM > Git >

Clone a remote repository using submodules in Git

Author:JIYIK Last Updated:2025/03/29 Views:

This article will discuss how to clone a remote Git repository using submodules. We will also create a submodule and push it to the remote repository before cloning it.


Clone a remote repository using submodules in Git

We clone our repository along with the submodules using the following command.

git clone --recurse-submodules -j8 git@github.com:KEVINAMAYI/AkanNameGenerator.git

Output:

Cloning into 'AkanNameGenerator'...
remote: Enumerating objects: 108, done.
remote: Counting objects: 100% (14/14), done.
remote: Compressing objects: 100% (11/11), done.
remote: Total 108 (delta 4), reused 3 (delta 1), pack-reused 94
Receiving objects: 100% (108/108), 2.38 MiB | 1.86 MiB/s, done.
Resolving deltas: 100% (29/29), done.
Submodule 'testfolder' (git@github.com:KEVINAMAYI/AkanNameGenerator.git) registered for path 'testfolder'
Cloning into '/home/kevin/tqt/AkanNameGenerator/testfolder'...
remote: Enumerating objects: 108, done.
remote: Counting objects: 100% (14/14), done.
remote: Compressing objects: 100% (11/11), done.
remote: Total 108 (delta 4), reused 3 (delta 1), pack-reused 94
Receiving objects: 100% (108/108), 2.38 MiB | 1.55 MiB/s, done.
Resolving deltas: 100% (29/29), done.
Submodule path 'testfolder': checked out '3300a2aa47ef2c490c19541c6907117511eabe08'

Create a submodule and push to the remote repository before cloning in Git

testfolderWe will first add a submodule named to the already existing local repository before cloning the repository and then push the changes to the remote repository.

<!-- this commands intializes a submodule with the contents of a remote repo-->
git submodule add <your remote repo url> <name of submodule>

git submodule add git@github.com:KEVINAMAYI/AkanNameGenerator.git testfolder

Output:

Cloning into '/home/kevin/tst/AkanNameGenerator/testfolder'...
remote: Enumerating objects: 105, done.
remote: Counting objects: 100% (11/11), done.
remote: Compressing objects: 100% (9/9), done.
remote: Total 105 (delta 3), reused 0 (delta 0), pack-reused 94
Receiving objects: 100% (105/105), 2.38 MiB | 2.06 MiB/s, done.
Resolving deltas: 100% (28/28), done.

Next, we check our new file. We should see an extra testfolder.

ls

Output:

css  images  index.html  js  LICENSE  README.md  testfolder  vendor

We will then commit the changes we just made.

git commit -m "Added the submodule to the project."

Output:

"Added the submodule to the project."
[main 500a12a] Added the submodule to the project.
2 files changed, 4 insertions(+)
create mode 100644 .gitmodules
create mode 160000 testfolder

We will use this command to push our changes to the remote repository.

git push

Output:

Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 4 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 429 bytes | 429.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To github.com:KEVINAMAYI/AkanNameGenerator.git
3300a2a..500a12a  main -> main

Now our remote repository has submodules testfolder.

Clone a repository with submodules

We will clone our repository and submodules.

git clone --recurse-submodules -j8 git@github.com:KEVINAMAYI/AkanNameGenerator.git 

Output:

Cloning into 'AkanNameGenerator'...
remote: Enumerating objects: 108, done.
remote: Counting objects: 100% (14/14), done.
remote: Compressing objects: 100% (11/11), done.
remote: Total 108 (delta 4), reused 3 (delta 1), pack-reused 94
Receiving objects: 100% (108/108), 2.38 MiB | 1.86 MiB/s, done.
Resolving deltas: 100% (29/29), done.
Submodule 'testfolder' (git@github.com:KEVINAMAYI/AkanNameGenerator.git) registered for path 'testfolder'
Cloning into '/home/kevin/tqt/AkanNameGenerator/testfolder'...
remote: Enumerating objects: 108, done.        
remote: Counting objects: 100% (14/14), done.        
remote: Compressing objects: 100% (11/11), done.        
remote: Total 108 (delta 4), reused 3 (delta 1), pack-reused 94        
Receiving objects: 100% (108/108), 2.38 MiB | 1.55 MiB/s, done.
Resolving deltas: 100% (29/29), done.
Submodule path 'testfolder': checked out '3300a2aa47ef2c490c19541c6907117511eabe08'

For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.

Article URL:

Related Articles

Fatal: Refusing to Merge Unrelated Histories error in Git

Publish Date:2025/03/29 Views:123 Category:Git

This article outlines the steps required to resolve the fatal: refusing to merge unrelated histories error in Git. We usually encounter such errors when trying to merge two unrelated Git projects into one branch. It pops up when the receivi

Using SSH keys to clone a repository or branch in Git

Publish Date:2025/03/29 Views:138 Category:Git

SSH Git cloning provides a secure way to clone remote repositories. This tutorial shows the complete method of Git cloning using SSH keys - how to generate SSH keys, set up SSH in Git, and use SSH keys for Git cloning. We also showed some u

Clone the repository in Git

Publish Date:2025/03/29 Views:146 Category:Git

Git is known as one of the best and most demanding version control systems for all developers around the world. As of now, it is a distributed version control system that utilizes its local repository and delegates the typical version contr

Clone Git using username and password

Publish Date:2025/03/29 Views:75 Category:Git

In this article, we will learn how to clone an existing repository using username and password in Git. In Git, we use the command git clone to clone an existing remote repository to our local computer. When we call git clone the command, we

Clone into a non-empty Git directory

Publish Date:2025/03/29 Views:108 Category:Git

This article will show you how to clone a Git repository to a non-empty folder. This operation comes in handy when you want to merge files from a remote repository with files in your current local repository. In Git, clone into a non-empty

Clone all branches in Git

Publish Date:2025/03/29 Views:132 Category:Git

When developing software using Git, you can create different branches for different features. This article will explain how to clone all different branches from remote to local in Git. Git clone all branches When using Git, you may need to

Clone a private repository in Git

Publish Date:2025/03/29 Views:106 Category:Git

This article will teach you how to use Git to clone a private repository hosted on Github. Git is a version control system used to track changes in a project directory. Git uses commits for such purposes. Github provides Internet hosting fo

Force pull overwrite in Git

Publish Date:2025/03/29 Views:119 Category:Git

Git is the most popular and demanded version control system today. The user interface of Git is similar to other version control systems. We can log in, clone the repository and make commits. However, Git has some significant differences th

Git authentication

Publish Date:2025/03/28 Views:163 Category:Git

This article demonstrates connecting a local repository to a remote repository on GitHub/Gitlab without getting 身份验证失败 error messages. Creating a local repository from scratch in Git To create a local repository from scratch, fo

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial