I keep the sub modules of a project in different repositories.
I host the sub modules in the Modules folder within the main project.
Submodules are ignored in the root project's .gitignore` file.
It's okay, but I want to create links to submodules on github.
I tried using Submodules. However, if I use submodules, I guess the folder contents (Modules/..
) must be empty.
How can I do that?
My local workspace:
RootFolder << user/RootFolder
├── .git
├── README.md
├── .gitignore
├── composer.json
└── Modules
├── Module1 << user/Module1
│ ├── .git
│ ├── README.md
│ └── composer.json
└── Module2 << user/Module2
├── .git
├── README.md
└── composer.json
RootFolder/.gitignore
content:
/Modules
It looks like this on Github. (As it's supposed to be)
user/RootFolder
├── README.md
└── composer.json
However, I want to create links with the same name as the ignored folders:
user/RootFolder
├── .gitignore
├── Modules
│ ├── Module1 >> Redirect to https://github.com/user/Module1 (How can I do that?)
│ └── Module2 >> Redirect to https://github.com/user/Module2 (How can I do that?)
├── README.md
└── composer.json
To convert your existing folder structure to use proper submodules:
Make sure that both the parent repository and the module repository do not have any changes. In other words, make sure that git status
tells you that you have nothing to commit, working tree clean
.
Move the current module repository out of the way, to back it up. In other words mv Modules/Module1 Modules/Module1.bak
.
Add it as a submodule: git submodule add -f https://github.com/path_to/module1 Modules/Module1
. The -f
is needed since Modules
still exists in your .gitignore
.
Make sure the file structure is as you like it. Run a build, test, etc. Run git status
to make sure that the .gitmodules
file and the module itself show up as staged changes. Commit the changes when you're happy with everything.
Repeat starting at step one until you've converted all your submodules.
Remove the backup module folders from the Modules
directory.
Remove /Modules
from your .gitignore
.
Congratulations(???) you now have submodules.