Git sub-module application

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.
Here Insert Picture Description

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.
Here Insert Picture Description
Submit the file to the remote repository
Here Insert Picture Description
you may have seen this document we have submitted a b.txt on Gitlab.
Here Insert Picture Description

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.
Here Insert Picture Description

git submodule update --remote
Published 76 original articles · won praise 16 · views 20000 +

Guess you like

Origin blog.csdn.net/weixin_38657051/article/details/103307832