1

I have added a submodule to a repo, however when I try to init and update the submodule, nothing happens.

There’s no output to the screen and no files appear in the submodule directory.

One slight complication is that the submodule is a private Github repo, however I’ve added a deploy key to the repo with the private key added as an ssh alias. I need to use ssh aliases because the action in which the code runs needs to access multiple private repos a bit later in the workflow.

ssh config contains:

Host github.com-id_rsa_data
  Hostname github.com
  IdentityFile=/home/runner/.ssh/id_rsa_data

Git .submodule file:

[submodule "_posts_from_sub/"]
    path = _posts_from_sub/
    url = https://github.com-id_rsa_data/<username-redacted>/test-data

Commands I run in the action step:

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

I tried adding —progress and —verbose to both commands but those options are not supported for git submodule.

Why doesn’t the test-data submodule get cloned after init and update are run?

Update to ssh config as per VonC:

[submodule "_posts_from_sub/"]
    path = _posts_from_sub/
    url = git@github.com-id_rsa_data/<username-redacted>/test-data

Also tried:

[submodule "_posts_from_sub/"]
    path = _posts_from_sub/
    url = git@github.com-id_rsa_data:<username-redacted>/test-data

and

[submodule "_posts_from_sub/"]
    path = _posts_from_sub/
    url = git+ssh://git@github.com-id_rsa_data:<username-redacted>/test-data
vy218
  • 707
  • 1
  • 8
  • 15

1 Answers1

0

An SSH config would imply an SSH URL, not an HTTPS one.

git@github.com-id_rsa_data:<username-redacted>/test-data

Only then your deploy key would be used.

You can change a submodule URL with:

git submodule set-url [--] <path> <newurl>

Check also if the folder referenced by <path> in your .gitmodules is a gitlink entry (or a regular folder)

git submodule status
git ls-tree main <path>

The approach the OP vy218 took in the comment was to create a regular nested git repository.

I decided to go ahead with using a regular git clone within the project.
It’s just a repo with data that is only ever read, not written to, so I don’t actually really need it to be a submodule.
It’s working now.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks for the comment. I updated the ssh config, see original question for details, however the submodule still does not install, and no output to console. – vy218 Oct 28 '22 at 06:08
  • Added a few more variations that I tried, including with the protocol. Any idea why it’s still not working? – vy218 Oct 28 '22 at 06:18
  • Do I need to use git submodule set-url or can I just edit the .submodule text file? – vy218 Oct 28 '22 at 06:24
  • You can edit the .git modules file, add, commit and push. Then try to clone again. – VonC Oct 28 '22 at 06:27
  • That’s what I did. None of the variations I tried and listed above work. What am I missing? – vy218 Oct 28 '22 at 06:38
  • If you already have a clone, editing the `.gitmodules` file won't edit the recorded URL within the `.git/config`. It will only affect *future* `git submodule update --init` operations that need to make a fresh clone. So you do still want to do that, but you want to go on to update the existing stored URL in the config. – torek Oct 28 '22 at 07:00
  • @vy218 The correct URL is the `git@github.com-id_rsa_data:/test-data` (using `:`, not '`/`'). Add commit and push your .gitmodules. Then clone again your repository, and see if a `git submodule update --init --recursive` works better. – VonC Oct 28 '22 at 08:16
  • @vy218 Check also your gitlink entry, as explained in my edited answer. – VonC Oct 28 '22 at 08:20
  • Thanks for your help. I was pressed for time and, since I couldn’t see any syntax error in what I had tried and was out of options, I decided to go ahead with using a regular git clone within the project. It’s just a repo with data that is only ever read, not written to, so I don’t actually really need it to be a submodule. It’s working now, but I might circle back around to this later if I have time and try to figure out why the submodule wasn’t working. – vy218 Oct 29 '22 at 12:13
  • @vy218 A valid workaround indeed. I have included your comment in the answer for more visibility. – VonC Oct 29 '22 at 12:19