Install and set up the GitLab for VS Code extension
To use the GitLab for VS Code extension, install the extension, connect to GitLab, and then configure it as needed.
Install the extension
Choose the installation method that meets your needs:
- For standard VS Code, install from the Visual Studio Marketplace.
- For unofficial VS Code versions, install from Open VSX Registry.
- For secure local development, install in a Visual Studio Code Dev Container.
Install in a Visual Studio Code Dev Container
For added security, set up the extension and use GitLab Duo in a containerized development environment using VS Code Dev Containers.
Prerequisites:
- Docker is installed and running.
- The Visual Studio Code Dev Containers extension is installed in VS Code.
To install the extension in a VS Code Dev Container:
Run the Dev Containers: Add Dev Container Configuration Files command from the Command Palette.
Add the GitLab extension to the configuration file:
// .devcontainer/devcontainer.json { "name": "My Project", "image": "mcr.microsoft.com/devcontainers/base:ubuntu", "customizations": { "vscode": { "extensions": [ "GitLab.gitlab-workflow" ] } } }Run the Dev Containers: Open Folder in Container command to open your project in a VS Code Dev Container. VS Code automatically installs the extension inside the container.
Connect to GitLab
After you install the extension, authenticate and then connect your project to a repository on GitLab.
Authenticate with GitLab
Prerequisites:
- A personal access token (PAT) with the
apiscope, if you use PAT authentication. - For OAuth authentication on GitLab Self-Managed or GitLab Dedicated, the ID of an OAuth application for VS Code.
To authenticate with GitLab:
- If you use OAuth on GitLab Self-Managed or GitLab Dedicated, configure the OAuth application login:
- In VS Code, select View > Command Palette.
- Type
Preferences: Open User Settingsand press Enter. - Select Settings > Extensions > GitLab > Authentication.
- Under OAuth Client IDs, select Add Item.
- Select Key and enter the GitLab instance URL.
- Select Value and enter the OAuth client ID.
- In VS Code, select View > Command Palette.
- Type
GitLab: Authenticateand press Enter. - Select your GitLab instance URL from the options or enter one manually.
- If you enter one manually, in URL to GitLab instance, paste the full URL,
including the
http://orhttps://. Press Enter to confirm.
- If you enter one manually, in URL to GitLab instance, paste the full URL,
including the
- Select an authentication method, OAuth or PAT.
- For OAuth, follow the prompts to sign in and authenticate.
- For PAT, follow the prompts to create a token or enter an existing one to authenticate.
The extension matches your Git repository remote URL with the GitLab instance URL you specified for your token. If you have multiple accounts or projects, you can choose the one you want to use.
If your GitLab instance or network uses a custom SSL setup, you can configure the extension to support self-signed certificates. For more information, see using the extension with self-signed certificates.
Configure with environment variables
Use environment variables to configure the extension when you:
- Delete your VS Code storage often, such as in Gitpod containers. Environment variables persist across storage deletions.
- Configure developer machines centrally and want to use the same variables as the GitLab CLI.
The extension reads two sets of variables. The extension does not combine variables from
different sets. For example, the extension never sends GITLAB_TOKEN to
GITLAB_WORKFLOW_INSTANCE_URL. If you set variables from both sets, the GITLAB_WORKFLOW_*
variables take priority.
The extension, the GitLab CLI, and the GitLab Duo plugin for JetBrains IDEs all read
GITLAB_HOST and GITLAB_TOKEN, so one configuration covers all three tools on your machine.
Use these variables when you can.
Environment variables support a personal access token only. They do not support OAuth.
The shared variables:
| Variable | Description |
|---|---|
GITLAB_HOST | Your GitLab instance URL or hostname. For example, https://gitlab.example.com. If you omit http:// or https://, the extension uses https://. |
GITLAB_TOKEN | Your personal access token for GITLAB_HOST. |
The variables that only the extension reads:
| Variable | Description |
|---|---|
GITLAB_WORKFLOW_INSTANCE_URL | Your GitLab instance URL, including http:// or https://. For example, https://gitlab.com. |
GITLAB_WORKFLOW_TOKEN | Your personal access token for GITLAB_WORKFLOW_INSTANCE_URL. |
GITLAB_WORKFLOW_TOKEN_FILE | The path to a file with your personal access token on the first line. The extension uses the file only when GITLAB_WORKFLOW_TOKEN is not set. |
To configure the extension with environment variables:
- Choose the shared variables or the extension-only variables.
- In your shell, system, or container, set the variables:
- For the shared variables, set
GITLAB_HOSTandGITLAB_TOKEN. - For the extension-only variables, set
GITLAB_WORKFLOW_INSTANCE_URLand eitherGITLAB_WORKFLOW_TOKENorGITLAB_WORKFLOW_TOKEN_FILE.
- For the shared variables, set
- Start or restart VS Code.
After you start VS Code, the extension behaves as follows:
- If you add an account in the extension, for any GitLab instance, the extension stops using
GITLAB_TOKEN. - The account from the
GITLAB_WORKFLOW_*variables stays available, even for the same GitLab instance. If both accounts are for the same instance, the extension cannot choose between them. The status bar shows Multiple GitLab Accounts until you select one. To choose which account to use, see switch accounts.
To avoid sharing a personal access token with other tools, authenticate with OAuth instead.
Connect to your repository
To connect to your GitLab repository from VS Code:
In VS Code, on the top menu, select Terminal > New Terminal.
Clone your repository:
git clone <repository>.Change to the directory where your repository was cloned and check out your branch:
git checkout <branch_name>.Ensure your project is selected:
- In the left sidebar, select GitLab ( ).
- Select the project name. If you have multiple projects, select the one you want to work with.
In the terminal, ensure your repository is configured with a remote:
git remote -v. The results should look similar to:origin git@gitlab.com:gitlab-org/gitlab.git (fetch) origin git@gitlab.com:gitlab-org/gitlab.git (push)If no remote is defined, or you have multiple remotes:
- In the left sidebar, select Source Control ( ).
- On the Source Control label, right-click and select Repositories.
- Next to your repository, select the ellipsis ( ), then Remote > Add Remote.
- Select Add remote from GitLab.
- Choose a remote.
The extension shows information in the VS Code status bar if both:
- Your project has a pipeline for the last commit.
- Your current branch is associated with a merge request.
Configure the extension
Change which account and project the extension uses, turn GitLab Duo features on or off, and set your telemetry level.
Manage accounts and projects
After you authenticate and connect to your repository, the extension chooses your GitLab account and project from your Git repository configuration. If you use multiple accounts or projects, use these tasks to switch accounts and to select or change the project.
Switch accounts
The extension uses one account for each VS Code workspace (window). It automatically selects the account when:
- You authenticate with only one GitLab account in the extension.
- All workspaces in your VS Code window use the same GitLab account, based on the
git remoteconfiguration.
If multiple GitLab accounts exist and the extension cannot determine which account to use, it adds Multiple GitLab Accounts ( ) to the status bar. To select a GitLab account, select the status bar item and follow the prompts.
Alternatively, you can use the Command Palette:
- In VS Code, select View > Command Palette.
- Run the command
GitLab: Select Account for this Workspace. - Select an account from the list.
Select a project
The extension uses your Git repository remote to determine which GitLab project to associate with your VS Code workspace.
When your Git repository has multiple remotes that point to different GitLab projects, the extension cannot determine which one to use. For example:
origin:git@gitlab.com:gitlab-org/gitlab-vscode-extension.gitpersonal-fork:git@gitlab.com:myusername/gitlab-vscode-extension.git
In these cases, the extension adds a (multiple projects) label to the status bar.
To select a project:
- In the left sidebar, select GitLab ( ).
- Expand Issues and merge requests.
- Select the line containing (multiple projects, click to select).
- Select a project from the list.
The Issues and merge requests list updates with your selected project’s information.
Change the project
To change your project selection:
- In the left sidebar, select GitLab ( ).
- Expand Issues and merge requests.
- Select the project.
- Next to the project name, select Clear Selected Project ( ).
Configure GitLab Duo
GitLab Duo features are enabled by default in VS Code when you meet the following prerequisites.
For all features:
- You have GitLab Duo turned on.
- Your project is in a group namespace.
- You have a default GitLab Duo namespace set or have a project open that has GitLab Duo access.
For specific features:
- For agentic features, you meet the prerequisites for GitLab Duo Agent Platform.
- For flows, you have foundational flows turned on.
- For agents, you have foundational agents turned on and custom agents turned on, as needed.
To approve Agentic Chat tools once per session instead of individually, see tool approvals.
Turn Code Suggestions on or off
Prerequisites:
- Meet the Code Suggestions prerequisites.
To turn Code Suggestions on or off in VS Code:
- In VS Code, open the Settings editor.
- Select Extensions > GitLab > GitLab Duo.
- Under GitLab › Duo Code Suggestions: Enabled, select or clear the checkbox.
- Optional. To turn off Code Suggestions for specific languages, see manage languages for Code Suggestions.
Alternatively, you can set gitlab.duoCodeSuggestions.enabled in the VS Code settings.json file.
Use Code Suggestions outside a GitLab project
To use Code Suggestions in files that are not part of a GitLab project:
- In VS Code, open the Settings editor.
- Select Extensions > GitLab > GitLab Duo > GitLab › Duo: Enabled Without GitLab Project.
Turn off GitLab Duo
To turn off GitLab Duo features in VS Code:
- In VS Code, open the Settings editor.
- Select Extensions > GitLab > GitLab Duo.
- Find the feature you want to turn off and clear the checkbox.
Configure telemetry
GitLab for VS Code uses the telemetry settings in Visual Studio Code to send usage and error information to GitLab. To turn on or customize telemetry in Visual Studio Code:
- In VS Code, open the Settings editor.
- Select Application > Telemetry.
- For Telemetry Level, select the data you want to share:
all: Sends usage data, general error telemetry, and crash reports.error: Sends general error telemetry, and crash reports.crash: Sends OS-level crash reports.off: Disables all telemetry data in Visual Studio Code.
- Save your changes.