Help Center> CodeArts Repo> Best Practices> Migrating the Repository to CodeArts Repo
Updated on 2023-10-26 GMT+08:00

Migrating the Repository to CodeArts Repo

This practice shows how to migrate your local or cloud repository to CodeArts Repo.

Application Scenario

With the development of code migration to the cloud, self-migration of repositories tends to be normal. CodeArts Repo provides a complete operation guide for you to migrate repositories to CodeArts Repo.

Principle

CodeArts Repo provides the following migration solutions based on the repository storage mode:

  • HTTP online import

    You can directly import your remote repository to CodeArts Repo through HTTP. However, the import duration is affected by network conditions and repository capacity.

    You are advised to use the Git client push mode to migrate cloud repositories with a large capacity.

  • Git client push
    Use the Git client to push code files in the local repository to CodeArts Repo.
    • For users who store project files on the local computer, you are advised to initialize the local project files to Git repository and then use the Git client for migration.
    • When you create a repository for a cloud repository with a large capacity, you are advised to clone or download the cloud repository to the local host, and then use the Git client to migrate the repository.

Prerequisites

  • A project is available. If no project is available, create one first.
  • A repository is available. If no repository is available, create one first.
  • During repository migration, ensure that the network is stable and smooth.
  • The capacity of the repository to be migrated cannot exceed 2 GB. Otherwise, the created repository will be frozen and cannot be used.

HTTP Online Import

  1. Go to the CodeArts homepage and click the target project name to access the project.
  2. Choose Code > Repo.
  3. On the CodeArts Repo page, click the icon next to New Repository and select Import Repository from the drop-down list box.
  4. On the Set Basic Information page, set the following parameters based on the site requirements:

    Table 1 External repository parameters

    Parameter

    Mandatory

    Description

    Source Repository URL

    Yes

    Enter a URL starting with http:// or https:// and ending with .git.

    Source Repository Access

    Yes

    • Username and password not required: Select this option if the source repository is open-source (public).
    • Username and password required: Select this option if the source repository is private, and enter the username and password for cloning HTTPS code.

  5. Select I have read and agree to the Privacy Statement and CodeArts Service Statement and click Next.
  6. On the Create Repository page, set the parameters in the following table.

    Table 2 Parameter description

    Parameter

    Mandatory

    Remarks

    Repository Name

    Yes

    The name must start with a letter, digit, or underscore (_) and can contain periods (.) and hyphens (-), but cannot end with .git, .atom. The name can contain a maximum of 200 characters.

    Description

    No

    Enter a description for your repository. The description can contain a maximum of 2,000 characters.

    Permissions

    No

    • Make all project developers automatic repository members

      By default, the project manager is automatically added as a repository member. If you select this option, the project developer is automatically added as a repository member.

    Visibility

    Yes

    The options are as follows:

    • Private

      The repository is visible only to repository members. Repository members can access the repository or commit code.

    • Public read-only

      The repository is open and read-only to all visitors. You can select an open-source license as the remarks.

    Branch

    Yes

    You can choose to synchronize the default branch or all branches of the source repository.

    Schedule

    No

    Select Schedule sync into repo.

    • The default branch of the source repository is automatically imported to the default branch of the new repository every day.
    • The repository becomes a read-only image repository and cannot be written. In addition, only the branches of the third-party repository corresponding to the default branch of the current repository are synchronized.

  7. Click OK. The repository list page is displayed.

Git Client Push (Git Bash Is Used as an Example)

Before pushing, ensure that SSH key or HTTPS password has been configured in the CodeArts Repo service.

  1. Access the target CodeArts Repo.
  2. Initialize the local repository to Git repository for association with CodeArts Repo.

    Open the Git Bash client in your repository and run the following command:

    git init

    The following figure shows that the initialization is successful. The current folder is the local Git repository.

  3. Bind the local repository to CodeArts Repo.

    1. Go to the CodeArts Repo and obtain the repository address.
    2. Run the remote command to bind the local repository to the cloud repository.
      git remote add <repository_alias> <repository_address>

      Example:

      git remote add origin git@*****/java-remote.git  # Change the address to that of your repository.
      • By default, origin is used as the repository alias when you clone a remote repository to the local computer. You can change the alias.
      • If the system displays a message indicating that the repository alias already exists, use another one.
      • If no command output is displayed, the binding is successful.

  4. Pull the master branch of the CodeArts Repo to the local repository.

    This step is performed to avoid conflicts.

    git fetch origin master  # Change origin to your repository alias.

  5. Commit local code files to the master branch.

    Run the following commands:

    git add .
    git commit -m "<your_commit_message>"

    The following figure shows a successful execution.

  6. Bind the local master branch to the CodeArts Repo master branch.

    git branch --set-upstream-to=origin/master master  # Change origin to your repository alias.

    The following figure is displayed, indicating that the merged repository has been placed in the working directory and repository.

  7. Merge the files in the CodeArts Repo repository and local repository and store them locally.

    git pull --rebase origin master   # Change origin to your repository alias.

    The following figure is displayed, indicating that the merged repository has been placed in the working directory and repository.

  8. Push the local repository to overwrite the CodeArts Repo repository.

    Run the push command because the repositories have been bound:

    git push

    After the operation is successful, pull the repository to verify that the version of the CodeArts Repo repository is the same as that of the local repository.