Other Git repository hosts
Supported on Enterprise plans.
Available via the Web app.
Site admins can sync Git repositories on any Git repository host (by Git clone URL) with Sourcegraph so that users can search and navigate the repositories. Use this method only when your repository host is not named as a supported code host.
To connect generic Git host to Sourcegraph:
- Go to Site admin > Manage code hosts > Add repositories
- Select Generic Git host.
- Configure the connection to generic Git host the action buttons above the text field, and additional fields can be added using
Cmd/Ctrl+Space
for auto-completion. See the configuration documentation below. - Press Add repositories.
Constructing the url
for SSH access
NOTE: Repository access over SSH is not yet supported on Sourcegraph Cloud.
If your code host serves git repositories over SSH, make sure your Sourcegraph instance can connect to your code host over SSH:
SHELLdocker exec $CONTAINER ssh -p $PORT $USER@$HOSTNAME
- $CONTAINER is the name or ID of your sourcegraph/server container
- $PORT is the port on which your code host's git server is listening for connections
- $USER is your user on your code host
- $HOSTNAME is the hostname of your code host from within the sourcegraph/server container (e.g.
githost.example.com
)
Here's an example:
SHELLdocker exec sourcegraph ssh -p 29418 [email protected]
The url
field is then
JSON"url": "ssh://$USER@$HOSTNAME:$PORT"`
Here's an example:
JSON"url": "ssh://[email protected]:29418",
Adding repositories
Elements of the repos
field are the same as the repository names. For example, a repository at https://githost.example.com/admin/repos/gorilla/mux will be "gorilla/mux"
in the repos
field.
Repositories must be listed individually:
JSON"repos": [ "gorilla/mux", "sourcegraph/sourcegraph" ]
Configuration
admin/code_hosts/other_external_service.schema.json
JSON{ // A list of repositories to never mirror by name after applying repositoryPathPattern. Supports excluding by exact name ({"name": "myrepo"}) or regular expression ({"pattern": ".*secret.*"}). "exclude": null, // Other example values: // - [ // { // "name": "myrepo" // }, // { // "pattern": ".*secret.*" // } // ] // Whether or not these repositories should be marked as public on Sourcegraph.com. Defaults to false. "makeReposPublicOnDotCom": false, "repos": null, // The pattern used to generate the corresponding Sourcegraph repository name for the repositories. In the pattern, the variable "{base}" is replaced with the Git clone base URL host and path, and "{repo}" is replaced with the repository path taken from the `repos` field. // // For example, if your Git clone base URL is https://git.example.com/repos and `repos` contains the value "my/repo", then a repositoryPathPattern of "{base}/{repo}" would mean that a repository at https://git.example.com/repos/my/repo is available on Sourcegraph at https://sourcegraph.example.com/git.example.com/repos/my/repo. // // It is important that the Sourcegraph repository name generated with this pattern be unique to this code host. If different code hosts generate repository names that collide, Sourcegraph's behavior is undefined. // // Note: These patterns are ignored if using src-expose / src-serve / src-serve-local. "repositoryPathPattern": "{base}/{repo}", // Other example values: // - "pretty-host-name/{repo}" // The root directory to walk for discovering local git repositories to mirror. To sync with local repositories and use this root property one must run Cody App and define the repos configuration property such as ["src-serve-local"]. "root": "", // Other example values: // - "path/to/my/repos" "url": null // Other example values: // - "https://github.com/?access_token=secret" // - "ssh://[email protected]:2333/" // - "git://host.xz:2333/" }
Configuration Notes
- Repository Path Pattern: The
repositoryPathPattern
field controls how repository names appear in Sourcegraph. Use{base}
for the clone URL base and{repo}
for the repository path. - Manual Repository Listing: Unlike other code hosts, repositories must be listed individually in the
repos
array - automatic discovery is not supported. - SSH Configuration: SSH access requires proper authentication setup between Sourcegraph and your Git server.
- Local Repository Support: Use the
root
field for syncing local Git repositories when using Cody App withsrc-serve-local
.
Security Considerations
- SSH Key Management: For SSH URLs, ensure SSH keys are properly configured and securely stored.
- Network Access: Verify Sourcegraph can reach your Git server on the required ports (SSH: 22, HTTP/HTTPS: 80/443).
- Authentication Tokens: For HTTPS URLs with tokens, store access tokens securely and rotate them regularly.
- Repository Visibility: Consider using
makeReposPublicOnDotCom
carefully to avoid exposing private repositories.
Common Examples
HTTPS Git Server
JSON{ "url": "https://git.example.com/repos", "repos": [ "project1/app", "project1/api", "project2/frontend" ], "repositoryPathPattern": "git.example.com/{repo}" }
SSH Git Server with Custom Port
JSON{ "url": "ssh://[email protected]:2222/", "repos": [ "infrastructure/ansible", "infrastructure/terraform" ], "repositoryPathPattern": "{base}/{repo}", "exclude": [ { "pattern": ".*temp.*" } ] }
Local Repository Sync
JSON{ "repos": ["src-serve-local"], "root": "/path/to/local/repos", "repositoryPathPattern": "local/{repo}" }
Git Server with Authentication Token
JSON{ "url": "https://git.example.com/?access_token=ghp_xxxxxxxxxxxx", "repos": [ "team-a/service1", "team-a/service2", "team-b/frontend" ], "repositoryPathPattern": "internal/{repo}" }
Best Practices
- Unique Repository Names: Ensure the
repositoryPathPattern
generates unique names that don't conflict with other code hosts. - Meaningful Patterns: Use descriptive patterns that help users identify the source of repositories (e.g.,
internal-git/{repo}
). - Regular Exclusions: Use
exclude
patterns to filter out temporary, test, or sensitive repositories. - Test Connectivity: Verify network connectivity and authentication before adding large numbers of repositories.
- Monitor Performance: Be mindful that manual repository listing doesn't scale as well as automatic discovery from other code hosts.