Back to Gitlabhq

Migrate through a Git URL

doc/user/project/import/repo_by_url.md

18.11.23.1 KB
Original Source

{{< details >}}

  • Tier: Free, Premium, Ultimate
  • Offering: GitLab.com, GitLab Self-Managed, GitLab Dedicated

{{< /details >}}

You can import your existing repositories by providing the Git URL. You can't import GitLab issues and merge requests this way. Other methods provide more complete import methods.

If the repository is too large, the import might time out.

You can import your Git repository by:

Prerequisites

{{< history >}}

  • Requirement for Maintainer role instead of Developer role introduced in GitLab 16.0 and backported to GitLab 15.11.1 and GitLab 15.10.5.

{{< /history >}}

  • Repository by URL import source must be enabled. If not enabled, ask your GitLab administrator to enable it. The Repository by URL import source is enabled by default on GitLab.com.
  • The Maintainer or Owner role on the destination group to import to.
  • If importing a private repository, an access token for authenticated access to the source repository might be required instead of a password.

Import a project by using the UI

  1. In the upper-right corner, select Create new ({{< icon name="plus" >}}) and New project/repository.
  2. Select Import project.
  3. Select Repository by URL.
  4. Enter a Git repository URL.
  5. Complete the remaining fields. A username and password (or access token) is required for imports from private repositories.
  6. Select Create project.

Your newly created project is displayed.

Import a timed-out project

Imports of large repositories might time out after three hours. To import a timed-out project:

  1. Clone the repository.

    shell
    git clone --mirror https://example.com/group/project.git
    

    The --mirror option ensures all branches, tags, and refs are copied.

  2. Add the new remote repository.

    shell
    cd repository.git
    git remote add new-origin https://gitlab.com/group/project.git
    
  3. Push everything to the new remote repository.

    shell
    git push --mirror new-origin
    

Import a project by using the API

You can use the Projects API to import a Git repository:

shell
curl --location "https://gitlab.example.com/api/v4/projects/" \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <your-token>' \
--data-raw '{
    "description": "New project description",
    "path": "new_project_path",
    "import_url": "https://username:[email protected]/group/project.git"
}'

Some providers do not allow a password and instead require an access token.