'How to make git submodule files available in parent repo?
I have this directory structure:
--/home/user/main_git_project
--main_files.txt
--sub_git_project
--sub_files.txt
I added the submodule with git submodule add <url> sub_git_project.
This created the /home/user/main_git_project/.gitmodules file successfully.
However, now when I git push the main git project and view the files at github the sub_git_project directory appears to be some type of symlink or placeholder (it is empty). There is no way to view or list the files in sub_git_project.
How can I add the sub_git_project to the main_git_project and have the sub_files be available?
Solution 1:[1]
I had a similar problem. Consider the following directory structure:
/home/<username>/<main-git-project>
.gitignore
.gitmodules
...<main-git-project> files
<submodule-git-project>
.gitignore
...<submodule-git-project> files
What I first attempted was to add the <submodule-git-project> submodule to my <main-git-project>, yielding the following .gitmodules file:
[submodule "<submodule-git-project>"]
path = <submodule-git-project>
url = ./<submodule-git-project>
I committed the changes in the <main-git-project> and pushed them to the remote GitHub repository. What happened is that the <submodule-git-project> folder was not clickable, thus not able to view any of its contents.
What I did to resolve the issue was to create a separate GitHub repository for the <submodule-git-project>, add the remote to the submodule, push the submodule code into this new repository, and edit the <main-git-project>'s .gitmodules file so the url now points to the remote submodule repository.
[submodule "<submodule-git-project>"]
path = <submodule-git-project>
url = https://github.com/<github-username>/<submodule-git-project>.git
Now the <main-git-project>'s GitHub repository has a hyperlink-styled <submodule-git-project>'s folder that redirects you to the submodule's GitHub repository.
This is a sample project I have in my account so you can better appreciate what I am talking about.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Alejandro Rodarte |
