Updated on 2024-12-11 GMT+08:00

Forking a Repository

Application Scenarios

The fork function can be used in large-scale projects with multiple sub-projects. You can fork a repository (an image) based on a repository and merge the CRs in the image to the source repository. When there is no merge, the modification of both the image repository and source repository will not affect each other.

As shown in the following figure, the complex development process occurs only in the image repository and does not affect the project version repo (source repo). Only the confirmed new features can be merged back to the project version repo. Therefore, fork is a team collaboration mode.

Differences Between Forking a Repository and Importing an External Repository

Both forking or importing a repo is a process of replication. The main difference lies in the association between the source repository and the copied repository. The details are as follows:

  • Fork
    • Forks are used to copy repositories on CodeArts Repo.
    • A fork generates a repository copy based on the current version of the source repository. You can apply for merging changes made on the fork to the source repository (cross-repository branch merge), but you cannot pull updates from the resource repository to the fork.
  • Import
    • You can import repositories of other version management platforms (mainly Git- and SVN-based hosting platforms) or your own repository to CodeArts Repo.
    • An import also generates a repository copy based on the current version of the source repository. The difference is that you can pull the default branch of the source repository to the repository copy at any time to obtain the latest version, but you cannot apply for merging changes made on the repository copy to the source repository.

Forking a Repository

  1. Access the repository list page.
  2. Click a repository name to go to the target repository.
  3. Click Fork in the upper right corner. In the displayed Fork Repository window, set parameters by referring to the following table.

    Table 1 Fork repository parameters

    Parameter

    Description

    Project

    Mandatory. Target project of the new repo. You can select a project name from the drop-down list.

    Path

    Optional. Target repo group path of the new repo. You can select a repo group path from the drop-down list.

    Repository

    Mandatory. Start with a letter, digit, or underscore (_). You can use letters, digits, hyphens (-), underscores (_), and periods (.). Do not end with .git, .atom, or periods (.).

    Visibility

    Mandatory. Indicates the visible scope of the source repo. The options are as follows:

    • Private: Only members of this repository can access it and commit code.
    • Public The value can be For project members, For tenant members, or For all guests.

    Synchronize commit rules of the source repository

    Optional. Indicates whether to synchronize the commit rules of the source repo. This option is selected by default, which means the source repo commit rules are synchronized. You can choose Settings > Policy Settings > Commit Rules to view the rule settings of the source repo and determine whether to select it.

  4. Click OK to fork the repository.

Checking the Fork Status of the Current Repo

  1. Access the repository list page.
  2. Click the source repository name.
  3. Click the number after Fork in the upper right corner of the page to view the list of forked repositories, as shown in the following figure. The current source repo is forked only once. Click the name in the Fork repo name column to go to the Code page of the forked repo.

Merging Changes of a Fork to the Source Repository

  1. Access the repository list page.
  2. Click the name of the forked repository.
  3. Click the Merge Requests tab.
  4. Click Create MR. On the Create MR page that is displayed, select a source branch and target branch to be merged.
  5. Click Next. On the Create MR page, set Title and Description, and click Create MR.

A cross-repository MR belongs to the source repository and can be viewed only on the Merge Requests tab of the source repository. Therefore, reviewers, scorers, approvers, and mergers must be members of the source repository.