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:
- For authentication using PAT, a personal access token with the
apiscope.
To authenticate with GitLab:
- Open the Command Palette:
- For macOS, press Command+Shift+P.
- For Windows or Linux, press Control+Shift+P.
- 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.
Prerequisites:
- For authentication using OAuth, the application ID for an OAuth application for VS Code.
- For authentication using PAT, a personal access token with the
apiscope.
To use OAuth, first configure the OAuth application login:
- Open the Command Palette:
- For macOS, press Command+Shift+P.
- For Windows or Linux, press Control+Shift+P.
- 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 ID of the OAuth application.
To authenticate with GitLab:
- Open the Command Palette:
- For macOS, press Command+Shift+P.
- For Windows or Linux, press Control+Shift+P.
- 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.
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
To configure settings, go to Settings > Extensions > GitLab.
Configure accounts and projects
After you authenticate and connect to your repository, the extension automatically associates your GitLab account and project based on your Git repository configuration.
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:
- Open the Command Palette:
- For macOS, press Command+Shift+P.
- For Windows or Linux, press Control+Shift+P.
- 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 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 prerequisites:
- For agentic features, you meet the prerequisites for GitLab Duo Agent Platform.
- You have GitLab Duo turned on.
- For flows, you have foundational flows turned on.
- For agents, you have foundational agents turned on and custom agents enabled, as needed.
- You have a default GitLab Duo namespace set or have a project open that has GitLab Duo access.
- For GitLab Duo Code Suggestions, you meet the additional prerequisites.
Turn off GitLab Duo
To turn off GitLab Duo features in VS Code:
- Select Extensions > GitLab.
- Select Manage ( ), and then select Settings > 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 Visual Studio Code, open settings:
- On macOS, go to Code > Settings > Settings.
- On Windows or Linux, go to File > Preferences > Settings.
- In the search bar, search for
Telemetry. - In the left sidebar, select 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.