Skip to content

Working with Git Submodules in CI/CD

When working with Git submodules in GitFlic CI/CD, manual initialization and cloning is required (for example, to build or test a project with external dependencies).

To learn more about Git submodules functionality, refer to this article.

Cloning Repository Submodules

To clone repository submodules, use git submodule update:

git submodule update --init --recursive

This command will load the submodules at the commits recorded in the main repository.

Fast Cloning

If there are many submodules or the repositories are large, use --depth 1 for faster cloning:

git submodule update --init --recursive --depth 1

The --depth 1 option clones submodules with only the latest commit, without the full history. This significantly saves space and time during cloning, especially in CI/CD.

Cloning Latest Changes from Branch

To initialize submodules with the latest commit from the branch specified in .gitmodules (instead of the recorded commit), use:

git submodule update --init --recursive --remote

Without running the git submodule update command, submodules will not be loaded!


Authorization for Private Submodules

If a submodule is private, you need to add authorization steps to your pipeline.

Method 1: Using the .netrc File

Add the following commands to your pipeline step:

before_script:
    - echo "machine gitflic.ru\nlogin $GITFLIC_USER\npassword $GITFLIC_TOKEN" > ~/.netrc
    - chmod 600 ~/.netrc
  • $GITFLIC_USER_LOGIN - predefined variable containing the user's login
  • $GITFLIC_TOKEN - user's password or repository deployment token

Note: When using a PowerShell agent on Windows, the .netrc method is not supported. For PowerShell agents on Windows, use method 2 or 3.


Method 2: Authorization via git config

Add the following command to your pipeline step:

before_script:
    - git config --global url."https://$GITFLIC_USER:$GITFLIC_TOKEN@gitflic.ru/".insteadOf "https://gitflic.ru/"

After running this command, any requests to submodules hosted on gitflic.ru will automatically use the specified authorization data.

Method 3: Using SSH Keys

  1. Generate an SSH key (if not already created):

    ssh-keygen -t ed25519 -C "powershell-runner"
    
  2. Add the public key to your GitFlic profile.

  3. Add the private key to your pipeline variables and use it for authentication:

    before_script:
        - mkdir -p ~/.ssh
        - echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_ed25519
        - chmod 600 ~/.ssh/id_ed25519
        - ssh-keyscan gitflic.ru >> ~/.ssh/known_hosts
    

Example gitflic-ci.yaml

build:
    stage: build
    variables:
        GITFLIC_TOKEN: <password_or_token>
    before_script:
        - echo "machine gitflic.ru\nlogin $GITFLIC_USER_LOGIN\npassword $GITFLIC_TOKEN" > ~/.netrc
        - chmod 600 ~/.netrc
        - git submodule update --init --recursive
    script:
        - ./build.sh

Automated translation!

This page was translated using automatic translation tools. The text may contain inaccuracies.