- Set up for self-managed GitLab instances
- Enable Sourcegraph in user preferences
- Using Sourcegraph code intelligence
- Sourcegraph for GitLab.com
- Sourcegraph and Privacy
Sourcegraph provides code intelligence features, natively integrated into the GitLab UI.
For GitLab.com users, see Sourcegraph for GitLab.com.
For an overview, watch the video Sourcegraph’s new GitLab native integration.
Before you can enable Sourcegraph code intelligence in GitLab you must:
- Enable the
sourcegraphfeature flag for your GitLab instance.
- Configure a Sourcegraph instance with your GitLab instance as an external service.
sourcegraphis enabled. This can be done from the Rails console by instance administrators.
Use these commands to start the Rails console:
# Omnibus GitLab gitlab-rails console # Installation from source cd /home/git/gitlab sudo -u git -H bin/rails console -e production
Then run the following command to enable the feature flag:
You can also enable the feature flag only for specific projects with:
If you are new to Sourcegraph, head over to the Sourcegraph installation documentation and get your instance up and running.
If you are using an HTTPS connection to GitLab, you must configure HTTPS for your Sourcegraph instance.
- Navigate to the site admin area in Sourcegraph.
- Configure your GitLab external service. You can skip this step if you already have your GitLab repositories searchable in Sourcegraph.
- Validate that you can search your repositories from GitLab in your Sourcegraph instance by running a test query.
- Add your GitLab instance URL to the
corsOriginsetting in your site configuration.
- On the top bar, select Menu > Admin.
- On the left sidebar, select Settings > General.
- Expand the Sourcegraph configuration section.
- Check Enable Sourcegraph.
- Set the Sourcegraph URL to your Sourcegraph instance, such as
If a GitLab administrator has enabled Sourcegraph, you can enable this feature in your user preferences.
- In the top-right corner, select your avatar.
- Select Preferences.
- In the Integrations section, select the checkbox under Sourcegraph.
- Select Save changes.
Once enabled, participating projects display a code intelligence popover available in the following code views:
- Merge request diffs
- Commit view
- File view
When visiting one of these views, you can now hover over a code reference to see a popover with:
- Details on how this reference was defined.
- Go to definition, which navigates to the line of code where this reference was defined.
- Find references, which navigates to the configured Sourcegraph instance, showing a list of references to the highlighted code.
Sourcegraph powered code intelligence is available for all public projects on GitLab.com.
Support for private projects is not yet available for GitLab.com; follow the epic &2201 for updates.
If you enabled Sourcegraph for your project but it isn’t working, Sourcegraph may not have indexed the project yet. You can check for Sourcegraph’s availability of your project by visiting
<project-path> with the path to your GitLab project.
From Sourcegraph’s extension documentation which is the engine behind the native GitLab integration:
Sourcegraph integrations never send any logs, pings, usage statistics, or telemetry to Sourcegraph.com. They connect only to Sourcegraph.com as required to provide code intelligence or other functionality on public code. As a result, no private code, private repository names, usernames, or any other specific data is sent to Sourcegraph.com.