How to push new repos + submodules to gitlab

Gitlab provides this method to push a new project directly to gitlab, without having to initialise it on the web-gui first. The following command works great:

git push --set-upstream master

I would like to do the same thing, but iterating over all submodules inside the new project. I’m trying to get the following command with submodule foreach to do that:

git submodule foreach --recursive 'sudo git push --set-upstream$project-name.git master'

But it fails like this:

Entering 'sub-repo-1'
> GitLab: The project you were looking for could not be found.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
Stopping at 'sub-repo-1'; script returned non-zero status.

In my use case, I have a project tree containing hundreds of submodules that I would like to push to gitlab. Eventually, I’d like to integrate that into a CI workflow, but first things first.

Any ideas why submodule foreach push-to-create doesn’t work?

Through trial and error I solved my own problem. It was a file name, permissions, and echoing issue. This command worked. Note that submodule foreach exposes the $name variable.

git submodule foreach --recursive 'git push --set-upstream`printf $name | sed "s/[^a-zA-Z0-9]/-/g"`.git master'