This write-up will explain different methods to list submodules in a Git repository.
How to List/Display Submodules in a Git Repository?
To list submodules in Git, multiple commands can be used, such as:
- “git submodule”
- “git submodule–helper list”
- “git submodule | awk ‘{ print $2 }’”
- “git submodule –quiet foreach –recursive ‘echo $name’”
- “grep path .gitmodules | sed ‘s/.*= //’”
- “git config –file .gitmodules –name-only –get-regexp path”
Method 1: List Submodules Using “git submodule” Command
To list all the submodules in the specified Git repository, execute the below-provided command:
In the below output, two submodules can be seen along with their repository name and SHA hash. More specifically, the “Repo1” repository contains the “Submod” submodule and the “test_Repo” repository contains the “TestSubmod” submodule:
Method 2: List Submodules Using “git submodule–helper list” Command
Utilize the “–helper list” option with the previous command to list the submodule with mode, SHA-hash value, stage, and their path:
In the below output:
- First column represents the mode of submodules.
- The SHA-hash value of submodules can be seen in the second column.
- The 3rd column shows the stage.
- The last column displays the submodules along their paths.
Method 3: List Submodules Using “git submodule | awk ‘{ print $2 }’” Command
To only view the names of submodules, use the “awk ‘{print $2}’” option with the same command:
The following command can also be utilized to list only the names of the Git submodules:
Another command to get only the names of submodules in the repository is given below:
Method 4: List Submodules Using “git config –file .gitmodules –name-only –get-regexp path” Command
Run the given-provided command to show all submodules entries in the repository:
We have explained different ways to list submodules in a Git repository.
Conclusion
Multiple Git commands can be used to list submodules in the Git repository, such as “git submodule”, and “git submodule–helper list” commands to display detailed information about the submodule. The “git submodule | awk ‘{ print $2 }‘”, “git submodule –quiet foreach –recursive ‘echo $name’” and “grep path .gitmodules | sed ‘s/.*= //’” lists only the names of the submodules. Furthermore, to display all submodule entries, utilize the “git config –file .gitmodules –name-only –get-regexp path” command. This write-up explained different methods to list submodules in a Git repository.