How to Pull the Latest Git Submodule

John Wachira Feb 02, 2024
  1. Pull the Latest Git Submodule
  2. Push Updates to a Git Submodule
  3. Clone a Git Submodule
How to Pull the Latest Git Submodule

In this article, we will introduce Git submodules. Under this, we will cover the following.

  1. The steps you can take to pull the latest submodule.
  2. How you can set up a submodule.
  3. How you can push updates into a Git submodule.
  4. How you can clone a submodule.

Working with Git allows you to create submodules in a parent repository. These submodules are child repositories stored in the directory of the parent repository.

Let’s see how you can set up and pull the latest submodule.

Pull the Latest Git Submodule

The command below initiates a submodule in our repository.

git submodule update --init --recursive

To pull the latest submodule, use the command below.

For Git versions 1.8.2 and above:

git submodule update --recursive --remote

For Git versions 1.7.3 and above, use:

git submodule update --recursive

An alternative command is:

git pull --recurse-submodules

Push Updates to a Git Submodule

Git treats submodules as separate repositories. So we can run the git push command in the submodule’s directory.

If you run the git status command in your parent repository, you should find your submodule in the Changes not staged for commit section. Before pushing the updates, you have to run the git add and git commit commands.

Clone a Git Submodule

You can clone a project containing submodules with the git clone command. However, the command will only clone directories without the files.

Run the git submodule init to update your local Git configuration and modules files to remedy the situation. Then run the git submodule update command to fetch the data from your parent repository.

Git submodules help you keep your projects organized. However, we do not advise using submodules in all your projects since the concept is tricky.

Author: John Wachira
John Wachira avatar John Wachira avatar

John is a Git and PowerShell geek. He uses his expertise in the version control system to help businesses manage their source code. According to him, Shell scripting is the number one choice for automating the management of systems.

LinkedIn

Related Article - Git Submodule