Create new git project: Is not valid HTTP Git repository

Viewed 114

I try create new git projects with files from the existing project: https://docs.gitlab.com/ee/api/projects.html#create-project

curl --request POST --header "PRIVATE-TOKEN: <your-token>" \
     --header "Content-Type: application/json" --data '{
        "name": "new_project", "description": "New Project", "path": "new_project",
        "import_url": "https://user:token@gitlab.com/<path>.git",
        "namespace_id": "42", "initialize_with_readme": "false"}' \
     --url 'https://gitlab.example.com/api/v4/projects/'

But I got the error:

{"message":"https://user:token@gitlab.com/<path>.git is not a valid HTTP Git repository"}

I was found the issue https://gitlab.com/gitlab-org/gitlab/-/issues/360266 with same error, but I set "initialize_with_readme": "false"

Gitlab version is 14.9.2

Also I tried use a broken url as import_url and got this error too

2 Answers

The issue you mentioned used:

https://user:token@gitlab.example.com/templates/someproject.git
        ^^^^^^^^^^                    ^^^^^^^^^^^^^^^^^^^^^
            |                         |- replace with your project/repo name
            |
            |- needed if the import project is private
               and need authentication to be accessed

That type of URL might work better in your case.


It this is somehow not supported, as in this thread (Apr. 2022) mentioned by the OP, the workaround is:

In any case we just worked around it by creating a blank project in the new GitLab, then pulling and pushing the project from the old one and into the new one.

This coding works well.

gitLabApi.getProjectApi().createProject(pro,"https://username:password@host/group/front-template.git");

enter image description here

Related