neo@MacBook-Pro ~ % cd workspace/Linux neo@MacBook-Pro ~/workspace/Linux % git submodule add https://github.com/netkiller/common.git common Cloning into '/Users/neo/workspace/Linux/common'... remote: Enumerating objects: 9, done. remote: Counting objects: 100% (9/9), done. remote: Compressing objects: 100% (8/8), done. remote: Total 185 (delta 2), reused 6 (delta 1), pack-reused 176 Receiving objects: 100% (185/185), 56.49 KiB | 163.00 KiB/s, done. Resolving deltas: 100% (105/105), done.
模組信息存儲在 .gitmodules 檔案中
neo@MacBook-Pro ~/workspace/Linux % cat .gitmodules [submodule "common"] path = common url = https://github.com/netkiller/common.git
同時也添加到 .git/config 檔案中
neo@MacBook-Pro ~/workspace/Linux % cat .git/config | tail -n 3 [submodule "common"] url = https://github.com/netkiller/common.git active = true
clone 項目,然後進入目錄
neo@MacBook-Pro /tmp/test % git clone https://github.com/netkiller/Linux.git neo@MacBook-Pro /tmp/test % cd Linux
初始化子模組
neo@MacBook-Pro /tmp/test/Linux % git submodule init Submodule 'common' (https://github.com/netkiller/common.git) registered for path 'common'
更新模組
neo@MacBook-Pro /tmp/test/Linux % git submodule update Cloning into '/private/tmp/test/Linux/common'... Submodule path 'common': checked out 'cdf61a1de34590bcc80b895fdf0e90b62cfd729f'