Using Perforce repositories with Sourcegraph

You can use Perforce repositories with Sourcegraph by using the git p4 adapter, which creates an equivalent Git repository from a Perforce repository. Sourcegraph doesn’t yet support Perforce repositories natively.

Screenshot of using Sourcegraph for code navigation in a Perforce repository:

Viewing a Perforce repository on Sourcegraph



  • Git
  • Perforce p4 CLI configured to access your Perforce repository
  • git p4 (see “Adding git p4 to an existing install”)
  • A Git host (such as GitHub or GitLab) where you can push new Git repositories

Create an equivalent Git repository from a Perforce repository

For each Perforce repository you want to use with Sourcegraph, follow these steps:

  1. Create a local Git repository with the contents of your Perforce repository: git p4 clone //DEPOT/[email protected] (replace //DEPOT/PATH with the Perforce repository path).
  2. cd PATH to enter the directory of the new local Git repository.
  3. Create a new Git repository on your Git host (such as GitHub or GitLab) for this repository.
  4. Add the repository you just created on the Git host as a remote: git remote add origin
  5. Push the repository to the Git host: git push -u origin master

Updating Perforce repositories

To update the repository after new Perforce commits are made, run git p4 sync && git push in the local repository directory. Sourcegraph does not yet automatically sync repositories from Perforce, so you must do this manually or script it yourself.

Add the converted Perforce repositories from your Git host to Sourcegraph

The repositories you created on your Git host are normal Git repositories, so you can add the repositories to Sourcegraph as you would any other Git repositories.

Known issues

We intend to improve Sourcegraph’s Perforce support in the future. Please file an issue to help us prioritize any specific improvements you’d like to see.

  • Sourcegraph was initially built for Git repositories only, so it exposes Git concepts that are meaningless for converted Perforce repositories, such as the commit SHA, branches, and tags.
  • There is no automatic updating of converted repositories when new Perforce commits are made. See the “Updating Perforce repositories” section for manual steps.
  • The commit messages for a Perforce repository converted to a Git repository have an extra line at the end with Perforce information, such as [git-p4: depot-paths = "//guest/acme_org/myproject/": change = 12345].