Help Center/ CodeArts Repo/ FAQs/ Fork Sync/ How Do I Sync Code from a Primary Database to a Derived Database Generated by Fork?
Updated on 2024-11-14 GMT+08:00

How Do I Sync Code from a Primary Database to a Derived Database Generated by Fork?

Symptom

In CodeArts Repo, you can fork the code repository of the primary repository to other projects for improved collaborative development. However, when the fork mode is used for development, the following problem may occur: After the primary repository (source project) is updated, you need to manually update the forked repository.

You can perform the following operations to sync the code of the primary library to the derived library generated by fork.

For example:

Primary repository address: https://test.com/f2e22eeb1b8c43cfb764765f5e3ff039/AlphaGo/TestService.git

Forked repository address: https://test.com/f2e22eeb1b8c43cfb764765f5e3ff039/Roger/TestService.git

Branch name: master

Solution

  1. Clone the forked repo in your personal space to the local host.

    git clone https://test.com/f2e22eeb1b8c43cfb764765f5e3ff039/Roger/TestService.git
    cd TestService

  2. Add the remote original repository (primary repository) to the local host. (You can run the git remote -v command to view the remote repository list.)

    git remote -v

  3. If there is no remote original repository, add the following information:

    git remote -v      
    origin  https://test.com/f2e22eeb1b8c43cfb764765f5e3ff039/Roger/TestService.git (fetch)      
    origin  https://test.com/f2e22eeb1b8c43cfb764765f5e3ff039/Roger/TestService.git (push)

  4. Check the remote repository list.

    git remote -v      
    origin  https://test.com/f2e22eeb1b8c43cfb764765f5e3ff039/Roger/TestService.git (fetch)      
    origin  https://test.com/f2e22eeb1b8c43cfb764765f5e3ff039/Roger/TestService.git (push)      
    main https://test.com/f2e22eeb1b8c43cfb764765f5e3ff039/AlphaGo/TestService.git (fetch)      
    main https://test.com/f2e22eeb1b8c43cfb764765f5e3ff039/AlphaGo/TestService.git (push)

  5. Obtain the latest branch code of the original repository (primary repository) to the local host and merge the code of the two versions.

    git pull main master

  6. Sync the latest merged code to the fork repository.

    git push origin master