git submodule添加子模塊(子倉庫)

在父倉庫中添加子倉庫

  1. 創建父倉庫(parent)
    clone地址:: https://gitee.com/xxx/parent.git

  2. 創建子倉庫(child1)
    clone地址:: https://gitee.com/xxx/child1.git

  3. 創建子倉庫(child2)
    clone地址:: https://gitee.com/xxx/child2.git

    注: 創建倉庫的時候勾選README.md,保證不是空倉庫

  4. 父倉庫添加子倉庫依賴
    第一步: 克隆父倉庫
    $ git clone https://gitee.com/xxx/parent.git
    第二步: 添加子倉庫
    $ git submodule add https://gitee.com/xxx/child1.git
    $ git submodule add https://gitee.com/xxx/child2.git
    第三步: push到父倉庫
    $ git add .
    $ git commit -m ‘add submodule’
    $ git push

    注: 當第二步(添加子倉庫)操作完成之後,項目中將生成…gitmodules文件
    文件內容如下:
    [submodule “child1”]
    path = child1
    url = https://gitee.com/xxx/child1.git
    [submodule “child2”]
    path = child2
    url = https://gitee.com/xxx/child2.git

  5. 遞歸克隆父倉庫
    $ git clone --recursive https://gitee.com/xxx/parent.git

  6. 更新子倉庫
    6.1 更新已存在的倉庫代碼
    git submodule foreach git pull origin master
    6.2 更新新增的子倉庫代碼
    git submodule update

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章