The following steps are based on the repository introduced in the previous section. They will explain how to turn a subdirectory of a project into an independent git repository and how to use this new repository as submodule, a foreign repository embedded within a dedicated subdirectory of the source tree of a project.
# this is parent repository ~/master/.git # this is another local repository ~/other/.git
IMPORTANT to make a backup both of folders. compress zip them (master and other).
Copy the .git folder from the local folder repository to the parent repository.
# copy ~/other/.git to ~/master/.git/modules/other/.git cp ~/other/.git ~/master/.git/modules/other/
Copy the other local repository to the parent repository.
# copy ~/other to ~/master/other cp ~/other ~/master/
Create .git file instead of folder. input following codes:
../.git/modules/other is located to
.gitmodules to the parent repository
put following codes to .gitmodules
[submodule "<path subfolder>"] path = <path subfolder> url = <url github repository> branch = <branch name of other local repository>
[submodule "other"] path = other url = https://github.com/dimaslanjaka/dimaslanjaka.github.io branch = posts
git submodule absorbgitdirs git submodule update --remote
- git add subfolder repository to submodule
- git add submodule from subfolder
- git add other subfolder git to submodule
- git move other repository as submodule