Authenticating Git with personal access token

You can securely clone a Git repository from your Control system. You can use it as a secure alternative to other Git authentication methods for accessing files in your dev container.

Before you begin

You must have performed the following task:

About this task

The following method outlines how to clone a Git repository in Code using a Personal Access Token (PAT).

Procedure

  1. Generate a Personal Access Token
    1. Navigate to your Settings in Control to generate a PAT.
    2. To generate a personal access token, click the Access Tokens tab in Settings.
    3. Add the Token Name, and set all permissions to Read and Write.
  2. Construct the clone URL for repository owned by username or organization ID
    1. The URL for cloning is structured with your username and the PAT. For example, assume your username is code@example.com, DevOps Loop is deployed at mydomain.com and your Control repository has the name repo-name, then the cloning URL will look like this:

      https://code-example.com:PAT@mydomain.com/control/code-example.com/repo-name

    2. Note that the @ in the username is replaced with a hyphen (-) in the URL.
    3. Replace PAT with the personal access token you generated in Control.
      Note:
      When creating a repository in Control, the Owner tab gives you two options: username or teamspace/organization ID. This choice dictates the correct structure for the clone URL.

      For a teamspace-owned repository, the teamspace ID must be used as the organization_identifier (the second-to-last part of the URL path) for the clone operation to succeed.

      https://code-example.com:a1b39ac1e546af4dc664ba36f4b12e77f8dad2da@mydomain.com/control/teamspace ID/repo-name

  3. Clone the Repository
    You can clone the repository either via the terminal or UI:
    Using Terminal:
    1. Run the full git clone command with the constructed URL

      git clone https://code-example.com:<PAT>@mydomain.com/control/code-example.com/repo-name

    Using UI:
    1. Go to the Source Control page in the IDE.
    2. Click the Clone Repository button in the UI.
    3. Paste the constructed clone URL into the input box.
    4. Choose the target folder (e.g., /usr/code/repos).
    5. Click Clone to start cloning.

Results

The Git repository is successfully cloned to your target folder. You can now begin working with the cloned files in your dev container.