Help Center/ CodeArts Repo/ User Guide/ Old Version/ Associating Cloud Repositories
Updated on 2023-07-25 GMT+08:00

Associating Cloud Repositories

If you have stored project files on the local computer, you need to initialize the local project files as a Git repository and associate them with a cloud repository provided by CodeHub before using CodeHub.

Prerequisites

You have installed the Git client and bound the SSH key of the Git client to CodeHub.

Procedure

  1. Create a remote repository.

    If you select gitignore based on your local code library, some non-development files will be ignored and will not be managed in Git.

  2. Initialize the local repository to a Git repository.

    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 the cloud repository.

    1. Go to the cloud repository 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 cloud repository 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 cloud master branch.

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

    If the following information is displayed, the binding is successful.

  7. Merge the files in the cloud 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 cloud repository.

    Run the push command directly because the repositories have been bound:

    git push

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