Submodule

Use Git Submodule to manage your file version

Add Submodule

1.Create submodule repository

If you create a KJModule repository for a submodule on the github, please make sure to commit once to let the whole repository is able to add it to another repository as a submodule

git@github.com:kejyun/KJModule.git

2.Add submodule

git submodule add <repository> [<path>]
git submodule add git@github.com:kejyun/KJModule.git ./app/KJModule

You have to specify the submodule repository and the submodule path

Fetch all of the files from the repository that with another submodule repository

1.Get the orignal repository

git clone git@github.com:kejyun/KJ.git

2.Initialize and update submodule

git submodule init
git submodule update

Change the path of the submodule

If you want to delete or update the submodule, then you have to update the .gitmodules files on the root path.

[submodule "app/KeJyunModule"]
	path = app/KeJyunModule
	url = git@github.com:kejyun/KeJyunModule.git
[submodule "app/KeJyunGroupModule"]
	path = app/KeJyunGroupModule
	url = git@github.com:kejyun/KeJyunGroupModule.git

You can find you submodule files in the hidden folder .git

.git/modules/<模組路徑>/config

vim ~/KeJyunProject/.git/modules/app/KeJyunModule/config

Update url from the [remote"origin"] on the config file to update the submodule path

[core]
	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true
	ignorecase = true
	precomposeunicode = true
	worktree = ../../../../app/KeJyunModule
[remote "origin"]
	url = git@github.com:kejyun/KeJyunModule.git
	fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
	remote = origin
	merge = refs/heads/master

clone and down all of the files and submodule on the repository

You can add --recursive argument to fetch all of the files and submodule on the repository

git clone --recursive git@github.com:kejyun/KJ.git

Update all the submodule files

You can use submodule to manage different project file on git. But the subodule might include another submodule. So you can run the following command to fetch all the files from submodule’s submodule.

git submodule update --init --recursive

Submodule hint

Because the submodule might have its own submodule. So the submodule might cause the recursive submodule problem to the infinite loop from fetching all the submodule files.

So the better way is to make a rule to include submodule to prevent the recursive submodule problem.

- Complicate Repositoy
	- Independent Component Repository Submodule
		- Independent Helper Method Repositoy Submodule

Update all the submodule files

Use Git Submodule to manage your file version: Update all the submodule files

Delete Submodule

Use Git Submodule to manage your file version: Delete Submodule