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:
- Read File system in the dev container.
- Read How to generate and use Personal Access Token in Control.
About this task
The following method outlines how to clone a Git repository in Code using a Personal Access Token (PAT).
Procedure
-
Generate a Personal Access Token
- Navigate to your Settings in Control to generate a PAT.
- To generate a personal access token, click the Access Tokens tab in Settings.
- Add the Token Name, and set all permissions to Read and Write.
-
Construct the clone URL for repository owned by username or organization
ID
- 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
- Note that the @ in the username is replaced with a hyphen (-) in the URL.
- 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
- 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:
-
Clone the Repository
You can clone the repository either via the terminal or UI:Using Terminal:
- 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:- Go to the Source Control page in the IDE.
- Click the Clone Repository button in the UI.
- Paste the constructed clone URL into the input box.
- Choose the target folder (e.g., /usr/code/repos).
- Click Clone to start cloning.
- Run the full git clone command with the constructed URL