Skip to content

private submodule checkout fails @v2 #116

Closed

Description

@tvainika

I've private git submodule, which contains our shared i18n resouces, with same organization owner as my main repo

I've configured git submodule in main repository as

$ cat .gitmodules
[submodule "xxx-i18n"]
	path = xxx-i18n
	url = ../xxx-i18n
	branch = master

Then I added this one from README to my github action workflow.

name: CI

on: [push]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
    - name: Checkout submodules
      shell: bash
      run: |
        auth_header="$(git config --local --get http.https://github.com/.extraheader)"
        git submodule sync --recursive
        git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=1

I expected this to work.

Instead I got

Checkout submodules
2s
##[error]Process completed with exit code 1.
Run auth_header="$(git config --local --get http.https://github.com/.extraheader)"
  auth_header="$(git config --local --get http.https://github.com/.extraheader)"
  git submodule sync --recursive
  git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=1
  shell: /bin/bash --noprofile --norc -e -o pipefail {0}
Submodule 'xxx-i18n' (https://github.com/myprivateorg/xxx-i18n) registered for path 'xxx-i18n'
Cloning into '/home/runner/work/my-main-repo/my-main-repo/xxx-i18n'...
remote: Repository not found.
fatal: repository 'https://github.com/myprivateorg/xxx-i18n/' not found
fatal: clone of 'https://github.com/myprivateorg/xxx-i18n' into submodule path '/home/runner/work/my-main-repo/my-main-repo/xxx-i18n' failed
Failed to clone 'xxx-i18n'. Retry scheduled
Cloning into '/home/runner/work/my-main-repo/my-main-repo/xxx-i18n'...
remote: Repository not found.
fatal: repository 'https://github.com/myprivateorg/xxx-i18n/' not found
fatal: clone of 'https://github.com/myprivateorg/xxx-i18n' into submodule path '/home/runner/work/my-main-repo/my-main-repo/xxx-i18n' failed
Failed to clone 'xxx-i18n' a second time, aborting
##[error]Process completed with exit code 1.

Activity

  1. eberkund commented on Dec 19, 2019

    @eberkund
  2. tvainika commented on Dec 19, 2019

    @tvainika
    Author

    Sub-modules support was removed in v2, I'm not sure why though

    I understood that it refers to another syntax with: submodules as the README I linked gives this new syntax I used.

  3. changed the title [-]submodule checkout fails @v2[/-] [+]private submodule checkout fails @v2[/+] on Dec 19, 2019
  4. da1nerd commented on Dec 27, 2019

    @da1nerd

    I also need to have sub-module support. When I use v2, there's no .git directory so I cannot perform any commands like checking out sub-modules. For now I'm using v1 to continue my development.

  5. rodrigorn commented on Dec 28, 2019

    @rodrigorn

    I have the exact same issue but I just made it work using the Checkout multiple repos (private) example

        - name: Checkout submodule
          uses: actions/[email protected]
          with:
            token: '${{ secrets.GITHUB_PAT }}'
            repository: myOrg/myRepo
            path: path/to/submodule
            ref: 'master'
    

    This is working just as a workaround and might not be practical for a project with a lot of submodules, but I hope it helps until #72 is resolved

  6. ashwinvis commented on Dec 28, 2019

    @ashwinvis

    @rodrigorn It works for some use cases. Even with a single submodule, it can become inconsistent when the master branch myOrg/myRepo adds commits which are not tracked by the main repo.

  7. jleni commented on Jan 2, 2020

    @jleni

    This is actually blocking us from using GitHub actions. I hope it can be prioritized..

  8. ericsciple commented on Jan 2, 2020

    @ericsciple
    Contributor

    @tvainika the default token embedded in the main repo does not have access to fetch other private repositories. Instead if you supply token: ${{ secrets.MY_GITHUB_PAT }} then it should work.

  9. ericsciple commented on Jan 2, 2020

    @ericsciple
    Contributor

    @neutrinog no .git folder indicates git 2.18 or higher is not in your PATH. I updated the readme earlier today to make that more clear.

  10. jleni commented on Jan 5, 2020

    @jleni

    I have the exact same issue but I just made it work using the Checkout multiple repos (private) example

        - name: Checkout submodule
          uses: actions/[email protected]
          with:
            token: '${{ secrets.GITHUB_PAT }}'
            repository: myOrg/myRepo
            path: path/to/submodule
            ref: 'master'
    

    This is working just as a workaround and might not be practical for a project with a lot of submodules, but I hope it helps until #72 is resolved

    @ericsciplec @rodrigorn is there a better alternative? I would like to avoid maintaining submodule hashes/branches in two different places. This is very error prone..

  11. m-hilgendorf commented on Jan 6, 2020

    @m-hilgendorf

    I'm having the same issue, came here from the readme where it has a section on "Checkout Submodules" that does not work at all for me (I can't checkout any submodule, public or private).

  12. rodrigorn commented on Jan 7, 2020

    @rodrigorn

    @ericsciplec @rodrigorn is there a better alternative? I would like to avoid maintaining submodule hashes/branches in two different places. This is very error prone..

    I agree completely but haven't found any better solution yet

  13. Lauszus commented on Jan 13, 2020

    @Lauszus

    FYI this is what I have been using:

    - name: Checkout submodule
      run: |
        git config --file=.gitmodules submodule.lib/YOUR_SUBMODULE.url https://${{ secrets.CI_PAT }}:${{ secrets.CI_PAT }}@github.com/ORG/YOUR_SUBMODULE.git
        git submodule sync
        git submodule update --init --recursive
  14. ashwinvis commented on Jan 13, 2020

    @ashwinvis

    @Lauszus is the CI_TOKEN a personal access token?

  15. Lauszus commented on Jan 13, 2020

    @Lauszus

    @ashwinvis yes it is. I have updated my comment to make it more clear.

  16. 68 remaining items

  17. sfullerbeckman commented on Sep 21, 2022

    @sfullerbeckman

    @jleni here's a version that will checkout all repositories defined in .gitmodules :)

    It works for both ssh and https:

    - name: Checkout submodules using a PAT
      run: |
        git config --file .gitmodules --get-regexp url | while read url; do
          git config --file=.gitmodules $(echo "$url" | sed -E "s/[email protected]:|https:\/\/github.com\//https:\/\/${{ secrets.CI_PAT }}:${{ secrets.CI_PAT }}@github.com\//")
        done
        git submodule sync
        git submodule update --init --recursive

    I get this error when trying to use your script...

    Run git config --file .gitmodules --get-regexp url | while read url; do
    sed: -e expression #1, char 86: unterminated `s' command

    The script look fine though. Do you know what the issue is @Lauszus ?

  18. Lauszus commented on Oct 3, 2022

    @Lauszus

    @jleni here's a version that will checkout all repositories defined in .gitmodules :)
    It works for both ssh and https:

    - name: Checkout submodules using a PAT
      run: |
        git config --file .gitmodules --get-regexp url | while read url; do
          git config --file=.gitmodules $(echo "$url" | sed -E "s/[email protected]:|https:\/\/github.com\//https:\/\/${{ secrets.CI_PAT }}:${{ secrets.CI_PAT }}@github.com\//")
        done
        git submodule sync
        git submodule update --init --recursive

    I get this error when trying to use your script...

    Run git config --file .gitmodules --get-regexp url | while read url; do
    sed: -e expression #1, char 86: unterminated `s' command
    

    The script look fine though. Do you know what the issue is @Lauszus ?

    From your error output it looks like you are running Windows. I don't think my script works with Windows.

  19. added a commit that references this issue on Nov 17, 2022
  20. asaf-kali commented on Apr 9, 2023

    @asaf-kali

    For anyone who gets here in the future, adding to @fbernaly's comment, when creating a PAT:

    1. Repository access -> Only select repositories -> Give access to both main repo and submodule repo.
    2. Permissions -> Repository permissions -> Give Read-only access to Contents and Metadata.

    image

  21. richw-kai commented on Jun 14, 2023

    @richw-kai

    It's a little concerning that the only solution here is to create a PAT. The point of a Github Action is to centralise the deployment process for an organisation, that organisation may have multiple private repositories, for example defining graphql or protobuf contracts. They need importing into each repo during the build process as submodules. To rely on PAT for this process is a security concern as well as an availability risk. If the person who creates the PAT leaves the company, the whole company will now be unable to deploy due to a quite deep down and hidden error within this process.

    What is the recommended solution for allowing an organisation to deploy code that references submodules from within their own organisation?

  22. sfullerbeckman commented on Jun 14, 2023

    @sfullerbeckman

    It's a little concerning that the only solution here is to create a PAT. The point of a Github Action is to centralise the deployment process for an organisation, that organisation may have multiple private repositories, for example defining graphql or protobuf contracts. They need importing into each repo during the build process as submodules. To rely on PAT for this process is a security concern as well as an availability risk. If the person who creates the PAT leaves the company, the whole company will now be unable to deploy due to a quite deep down and hidden error within this process.

    What is the recommended solution for allowing an organisation to deploy code that references submodules from within their own organisation?

    Oh that is true, @richw-kai. I didn't think of that issue with the PAT. I was so focussed on getting it to work in the first place!

  23. charlielito commented on Jun 14, 2023

    @charlielito

    It's a little concerning that the only solution here is to create a PAT. The point of a Github Action is to centralise the deployment process for an organisation, that organisation may have multiple private repositories, for example defining graphql or protobuf contracts. They need importing into each repo during the build process as submodules. To rely on PAT for this process is a security concern as well as an availability risk. If the person who creates the PAT leaves the company, the whole company will now be unable to deploy due to a quite deep down and hidden error within this process.

    What is the recommended solution for allowing an organisation to deploy code that references submodules from within their own organisation?

    Because of that, I use GitHub App Installation access tokens which are not directly tied to a user but instead tied to the GitHub App installed in your organization. I use this action to use a previously configured and installed GitHub App to get a special token with more privileges (like access to other organization repos). This other action also seems to do the same. Then, my action would look like:

    name: Some test
    on:
      pull_request:
    jobs:
      some_job:
        runs-on: ubuntu-22.04
        name: Some action
        steps:
          - name: Get token
            id: get_token
            uses: machine-learning-apps/actions-app-token@master
            with:
              APP_PEM: ${{ secrets.AUTH_APP_PEM }}
              APP_ID: ${{ secrets.AUTH_APP_ID }}
          - name: Checkout repository and submodules
            uses: actions/checkout@v3
            with:
              submodules: recursive
              token: ${{ steps.get_token.outputs.app_token }}
  24. mcolussi-bigw commented on Aug 4, 2023

    @mcolussi-bigw

    Because of that, I use GitHub App Installation access tokens which are not directly tied to a user but instead tied to the GitHub App installed in your organization.

    This worked for me and probably the best solution so far to not tie the submodule checkout permissions to a specific user. The only requirement is the GitHub App needs the read-only to the "Contents" permission.

  25. Cloudef commented on Sep 15, 2023

    @Cloudef

    Can't believe there's still no better way to do this

  26. zealcc commented on Jan 29, 2024

    @zealcc

    how can i checkout submodules on pull reqeust ???

          - name: Checkout
            if: github.actor == 'dependabot[bot]'
            uses: actions/checkout@v3
            with:
              token: ${{ github.token }}
              submodules: recursive
    
          - name: Checkout
            if: github.actor != 'dependabot[bot]'
            uses: actions/checkout@v3
            with:
              token: ${{ secrets.GH_PAT }}
              submodules: recursive
    

    ${{ github.token }} -> can't checkout submodules -> pull-request can use github.token
    ${{ secrets.GH_PAT }} -> can checkout submodules -> pull-request can't use secrets

  27. sfullerbeckman commented on Jan 29, 2024

    @sfullerbeckman

    This worked for me. After checking out the main repository, my pipeline runs this action to checkout any submodules. It's a little bit hacky, but it has worked for me.

    - name: Checkout the repo
            uses: actions/[email protected]
            with:
              persist-credentials: false
    
    - name: Checkout submodule
            run: |
              git submodule sync --recursive
              git -c protocol.version=2 submodule update --init --force --depth=1 --recursive
  28. parth-hb commented on Jun 30, 2025

    @parth-hb

    I faced same issue and struggled atleast 2 days to make it work. If you're also struggling with the same, here's a reliable and tested fix using Deploy Keys.

    Steps

    1. Generate an SSH Key

      ssh-keygen -t rsa -b 4096 -C "ci-access" -f submodule_deploy_key
    2. Add Public Key to Submodule Repo

      • Go to your submodule repo (e.g., my-org/my-redux-store)
      • Navigate to: Settings → Deploy Keys
      • Click "Add deploy key", paste the public key from submodule_deploy_key.pub
      • Make sure to enable Allow write access if required
    3. Add Private Key to Main Repo Secrets

      • Go to your main repo (my-org/my-app)
      • Add a secret like SUBMODULE_SSH_KEY
      • Paste contents of submodule_deploy_key (the private key)
    4. Modify Workflow
      Before updating submodules, add:

      - name: Checkout main repo (no submodules)
        uses: actions/checkout@v4
        with:
           submodules: false
             
      - name: Setup SSH for submodules
        run: |
          mkdir -p ~/.ssh
          echo "${{ secrets.SUBMODULE_SSH_KEY }}" > ~/.ssh/id_rsa
          chmod 600 ~/.ssh/id_rsa
          ssh-keyscan github.com >> ~/.ssh/known_hosts
      
       - name: Init and update submodules
         run: |
          git submodule sync
          git submodule update --init --recursive
      

    This should fix the common Permission denied or Repository not found errors when dealing with submodules.


    Works great when:

    • You don’t want to use personal tokens
    • You want tight access control over a single repo
    • You prefer SSH over HTTPS
  29. parth-hb commented on Jun 30, 2025

    @parth-hb

    I faced same issue and struggled atleast 2 days to make it work. If you're also struggling with the same, here's a reliable and tested fix using Deploy Keys.

    Steps

    1. Generate an SSH Key

      ssh-keygen -t rsa -b 4096 -C "ci-access" -f submodule_deploy_key
    2. Add Public Key to Submodule Repo

      • Go to your submodule repo (e.g., my-org/my-redux-store)
      • Navigate to: Settings → Deploy Keys
      • Click "Add deploy key", paste the public key from submodule_deploy_key.pub
      • Make sure to enable Allow write access if required
    3. Add Private Key to Main Repo Secrets

      • Go to your main repo (my-org/my-app)
      • Add a secret like SUBMODULE_SSH_KEY
      • Paste contents of submodule_deploy_key (the private key)
    4. Modify Workflow
      Before updating submodules, add:

      - name: Checkout main repo (no submodules)
        uses: actions/checkout@v4
        with:
           submodules: false
             
      - name: Setup SSH for submodules
        run: |
          mkdir -p ~/.ssh
          echo "${{ secrets.SUBMODULE_SSH_KEY }}" > ~/.ssh/id_rsa
          chmod 600 ~/.ssh/id_rsa
          ssh-keyscan github.com >> ~/.ssh/known_hosts
      
       - name: Init and update submodules
         run: |
          git submodule sync
          git submodule update --init --recursive
      

    This should fix the common Permission denied or Repository not found errors when dealing with submodules.


    Works great when:

    • You don’t want to use personal tokens
    • You want tight access control over a single repo
    • You prefer SSH over HTTPS
  30. davidt-gh commented on Jul 8, 2025

    @davidt-gh

    Why is that closed if the issue never solved?

  31. NicolasGonzalezFarabollini commented on Jul 31, 2025

    @NicolasGonzalezFarabollini

    You can bypass this issue if you use the token inside a docker instance on github actions. Yes, not the most efficient, nor elegant. But it works.

    For example, I just need to build a dependency from a private repo under same org. I make the yarn build inside the docker image, validate with token. Next, I extract the files from the docker image, and continue the build process with normal github steps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions