Adding a Submodule (Optional/Advanced)

Last update: 05 Jul 2023 [History] [Edit]

Throughout your research and your ATLAS analysis, you will have to use external packages. Maybe this is code written by someone else for a specific task or it might be helper code you have written yourself previously.

To keep track of these and link them to your analysis code you can use what is called a Submodule. This is a feature in git that allows it to keep track of another repository within your repository, a snapshot in time of an external package.

Let’s add a dummy package called JetSelectionHelper as a submodule. The GitLab page for this package can be found here, make a fork of this repository.

git submodule add<username>/JetSelectionHelper.git 

After this package has been cloned you should see a .gitmodules file when you do ls -a and has appeared when you run git status.

$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#	new file:   .gitmodules
#	new file:   JetSelectionHelper

The .gitmodules file will now contain the relative path to the submodule and the remote

[submodule "JetSelectionHelper"]
  path = JetSelectionHelper
  url =<username>/JetSelectionHelper.git

Go ahead and add, commit and push this all to your repository on GitLab, you have successfully added an external package as a submodule.

git add .gitmodules JetSelectionHelper
git commit -m "<insert commit message>"
git push -u origin master

This is an example of how things should now look (please use more informative commit messages)