Git sub-module application
- First, the introduction of sub-module
- Second, create a sub-module
- 2.1, the repository directory structure of the tape module
- 2.2, create test-project repository
- 2.3, create test-project-doc Document Repository
- 2.4, document libraries into the project repository
- Third, pull the tape module project
- Fourth, work on the project includes sub-modules
First, the introduction of sub-module
git submodule introduce
a demand, we are trying to separate items in the code and documentation, and all add permissions. That some people have permission to download the project documentation, some people only the code relevant permissions. This gitlab do not have this feature, but can be achieved through git submodule.
Second, create a sub-module
2.1, the repository directory structure of the tape module
First of all, after we complete the project directory is probably as shown below. test-project-doc documentation for the project, then the code can be used as test.txt.
2.2, create test-project repository
the difference between git init and git --bare init that:
git init with work area
git --bare init is without a workspace, only the repository, you want to see the contents inside the only git clone git clone address by the way out
git init --bare test-project.git
git clone test-project.git test-project
cd test-project
echo "This is a project." > text.txt
git add .
git commit -m "add text.txt"
git push origin master
2.3, create test-project-doc Document Repository
git init --bare test-project-doc.git
git clone test-project-doc.git test-project-doc
cd test-project-doc
echo "This is a submodule test-project-doc." > a.txt
git add .
git commit -m "add a.txt"
git push origin master
2.4, document libraries into the project repository
cd test-project
git submodule add ../test-project-doc.git test-project-doc
git status
git diff
git add .
git commit -m "add submodule test-project-doc"
git push origin master
Third, pull the tape module project
3.1, clone parent project test-project
Next we'll clone a project with sub-modules. When you clone this project, sub-module that contains the default directory, but test-project-doc are not yet any document:
git clone http://192.168.2.99:8089/domestic-group/test-project.git
cd test-project
You have to run two commands: git submodule init to initialize the local configuration file, and git submodule update from the project to crawl all the data and submit the appropriate detection parent item listed.
git submodule init
git submodule update
3.2, an easy way to clone the tape library project
But there is a little more simple way. If the git clone command to transfer --recursive option, it will automatically update each sub-module initialization and warehouse.
git clone --recursive http://192.168.2.99:8089/domestic-group/test-project.git
Fourth, work on the project includes sub-modules
4.1, add a b.txt file test-project-doc document library and upload to the remote library
In test-project-doc folder, create a file b.txt. Content This is b.
Submit the file to the remote repository
you may have seen this document we have submitted a b.txt on Gitlab.
4.2, updating the code on another device, download b.txt file.
As shown below, a start test-project-doc file on this device only a.txt file folder. Then execute the update command, you can see that we have to pull the b.txt file.
git submodule update --remote