User Tools

Site Tools


git:git-submodules

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
git:git-submodules [2024/11/30 17:17] admingit:git-submodules [2024/12/12 08:44] (current) admin
Line 3: Line 3:
 If you clone a git repo inside you git, the best way to handle it is to use modules (sub modules). If you clone a git repo inside you git, the best way to handle it is to use modules (sub modules).
  
-====== Create a submodule ======+==== Create a submodule ====
  
 To define a submodule you can use : To define a submodule you can use :
Line 18: Line 18:
 git submodule add https://gitlab.com/bnzr/python_control_coppeliasim.git external/python_control_coppeliasim/ git submodule add https://gitlab.com/bnzr/python_control_coppeliasim.git external/python_control_coppeliasim/
 </code>   </code>  
 +
 +==== List all submodules ====
  
 We can list the submodules with : We can list the submodules with :
Line 25: Line 27:
  
 Information on submodules can be found in  **.gitmodules** and **.git/config** of the main project git Information on submodules can be found in  **.gitmodules** and **.git/config** of the main project git
 +
 +==== Content changes in submodules ==== 
  
 If we add the changes, commit and push , the content of submodules will not been added in the main project git, but information on how to retrieve it will be stored. In our example we push the changes : If we add the changes, commit and push , the content of submodules will not been added in the main project git, but information on how to retrieve it will be stored. In our example we push the changes :
Line 32: Line 36:
 git push git push
 </code> </code>
 +
 +==== Clone git repo with submodules ====
  
 In another computer we can simply clone the main project repo and we will see that there is nothing in the submodule. The content of the submodules can be pulled by  In another computer we can simply clone the main project repo and we will see that there is nothing in the submodule. The content of the submodules can be pulled by 
Line 49: Line 55:
 git submodule foreach git restore . git submodule foreach git restore .
 </code> </code>
 +
 +==== Working with a particular submodule (not all) ====
 +
 +If the main git repo contains many submodules, it can be interesting to work only on one particular submodule.
 +For example, if after cloning the main git repo the submodule contains nothing, it can be cloned independently of the others submodules. 
 +Suppose the path to submodule (from main repo path) is /path/to/mysubmodule, to clone it type :
 +<code bash>
 +git submodule init /path/to/mysubmodule
 +git submodule update -- /path/to/mysubmodule
 +</code>
 +If the submodule is not in the correct branch, these commands can be used to list the branches and set to the correct one (ex master)
 +<code bash>
 +git -C /path/to/mysubmodule branch
 +git -C /path/to/mysubmodule checkout master
 +</code>
 +In general a git **command** on submodule can be acheived from main git repo by :
 +<code bash>
 +git -C /path/to/mysubmodule command
 +</code>
 +
  
  
git/git-submodules.1732983427.txt.gz · Last modified: 2024/11/30 17:17 by admin