|
| 1 | +--- |
| 2 | +title: Searching multiple branches and tags |
| 3 | +sidebarTitle: Searching multiple branches |
| 4 | +--- |
| 5 | + |
| 6 | +By default, only the default branch of a repository is indexed and can be searched. Sourcebot can be configured to index additional branches (or tags) enabling multi-branch search. This is useful for scenarios such as: |
| 7 | + |
| 8 | +- Searching across different releases |
| 9 | +- Searching through feature branches during development |
| 10 | +- Tracking changes across multiple maintenance branches simultaneously |
| 11 | + |
| 12 | +## Configuration |
| 13 | + |
| 14 | +<Warning> |
| 15 | +Multi-branch indexing is currently limited to 64 branches and tags. If this limitation impacts your use-case, please [open a discussion](https://github.com/sourcebot-dev/sourcebot/discussions/categories/support). |
| 16 | +</Warning> |
| 17 | + |
| 18 | +Multi-branch indexing is configured on in the [connection](/docs/connections/overview) using the `revisions.branches` and `revisions.tags` arrays. Glob patterns are supported. For example: |
| 19 | + |
| 20 | +```json |
| 21 | +{ |
| 22 | + "$schema": "https://raw.githubusercontent.com/sourcebot-dev/sourcebot/main/schemas/v3/index.json", |
| 23 | + "connections": { |
| 24 | + "my-connection": { |
| 25 | + "type": "github", |
| 26 | + // For each of the repositories defined in this connection... |
| 27 | + "repos": [ |
| 28 | + "org/repo1", |
| 29 | + "org/repo2" |
| 30 | + ], |
| 31 | + // ... index the default branch, as well as... |
| 32 | + "revisions": { |
| 33 | + // These branches (if they exist): |
| 34 | + "branches": [ |
| 35 | + // Exact matches |
| 36 | + "dev", |
| 37 | + "staging", |
| 38 | + |
| 39 | + // Glob patterns |
| 40 | + "feature/*" // Matches: feature/auth, feature/ui, etc. |
| 41 | + ], |
| 42 | + |
| 43 | + // These tags (if they exist): |
| 44 | + "tags": [ |
| 45 | + // Exact matches |
| 46 | + "v4.0.0-dev", |
| 47 | + |
| 48 | + // Glob patterns |
| 49 | + "v3.*.*", // Matches: v3.0.0, v3.0.1, etc. |
| 50 | + "rc-*" // Matches: rc-1, rc-2, etc. |
| 51 | + ] |
| 52 | + } |
| 53 | + } |
| 54 | + } |
| 55 | +} |
| 56 | +``` |
| 57 | + |
| 58 | +For each repo defined in the connection, any branches or tags matching the patterns in `branches` and `tags` array will be indexed. |
| 59 | + |
| 60 | +## Search syntax |
| 61 | + |
| 62 | +To search branches other than the default, the `rev:` prefix can be used followed by the branch (or tag) name: |
| 63 | + |
| 64 | +| Example | Explanation | |
| 65 | +| :--- | :--- | |
| 66 | +| `rev:feature/foo repo:A useEffect` | Search for `/useEffect/` on branch `feature/foo` in repo `A` | |
| 67 | +| `rev:feature/foo useEffect ` | Search for `/useEffect/` on branch `feature/foo` across all repos | |
| 68 | +| `rev:feature/ useEffect` | Search for `/useEffect/` on branches that contain `feature/` across all repos | |
| 69 | +| `rev:feature/a rev:feature/b foo` | Search for `/foo/` on branches `feature/a` and `feature/b` | |
| 70 | +| `rev:feature/ -rev:feature/a foo` | Search for `/foo/` on branches that contain `feature/` _except_ for `feature/a` across all repos | |
| 71 | + |
| 72 | +To search across **all** branches, `rev:*`: |
| 73 | +| Example | Explanation | |
| 74 | +| :--- | :--- | |
| 75 | +| `rev:* repo:A "error message"` | Search for `/error message/` across **all** branches in repo `A` | |
| 76 | +| `rev:* "error message"` | Search for `/error message/` across **all** branches and **all** repos | |
| 77 | + |
| 78 | +Additional info: |
| 79 | +- `refs/heads/` or `refs/tags/` can be included to fully qualify a branch or a tag, respectively. E.g., `rev:refs/heads/foo` will search the branch `foo`, while `rev:refs/tags/foo` will search the tag `foo`. |
| 80 | +- `rev:` does **not** support regular expressions or glob patterns. It uses a simple `contains` call between the branch name and the pattern. See [here](https://github.com/sourcebot-dev/zoekt/blob/7d1896215eea6f97af66c9549c9ec70436356b51/matchtree.go#L1067). |
| 81 | + |
| 82 | + |
| 83 | +## Platform support |
| 84 | + |
| 85 | +| Platform | Multi-branch indexing support | |
| 86 | +|:----------|------------------------------| |
| 87 | +| GitHub | ✅ | |
| 88 | +| GitLab | ✅ | |
| 89 | +| Bitbucket Cloud | ✅ | |
| 90 | +| Bitbucket Data Center | ✅ | |
| 91 | +| Gitea | ✅ | |
| 92 | +| Gerrit | ❌ | |
| 93 | + |
0 commit comments