Search in Bitbucket Cloud
To start searching in Bitbucket, select the search field in the top navigation bar. The keyboard shortcut to start a search from anywhere in Bitbucket is "/".
Search results in Bitbucket are code first and you can also use operators or modifiers to help you to refine search results. While you are searching, notice that you are provided with ways to refine your search, a list of recent searches, and a list of repositories that you may be searching for.
Search scopes
The scope of a search changes according to where you are searching from:
Search context/location | Search scope |
|---|---|
Workspace | All repositories in a workspace accessible to a user |
Repository | An individual repository and its sub-directories |
Access repository-level code search
To search for code within a specific repository, go to the repository, select the dropdown in the search field (it is set to Files by default), and then select Code from the dropdown menu.
Phrase queries
A phrase query can be used to find multiple words that appear in a specific order.
To search for a phrase, enclose the words in double quotes. For example, to find files with instances of the word abstract followed by the word class, your query would look like this.
"abstract class"The same search query without the double quotes would return files that contain both abstract and class in any order. For example, a query for abstract class means that only files that contain both abstract and class are matched.
Search modifiers
Modifiers can be used to refine search results:
Use a modifier in the form
key:value.The modifier field name is case-sensitive,
REPO:myrepowill throw an error.You can combine multiple modifiers; they are combined with
ANDby default.
These are the search modifiers available:
Modifier | Example query | Results |
|---|---|---|
Note: You can also use |
| Matches files in
|
|
| Files with paths matching
|
|
Note: do not include the dot delimiter, i.e. | Matches files with the |
Note: You can also use |
| Matches C files with the |
Note: |
Note: the | Matches files from repository forks that contain the term
|
Project-level search coming back soon
We are working on implementing the project-level search modifiers that previously existed into the new search experience. Thanks for your patience.
Path modifier
Code search can be restricted to only consider a particular path. For the purpose of search, file paths are split up into segments (parts separated by /) including directories and filenames. Matching is done on one or more segment and is case-insensitive.
There is no partial matching within a segment. This means path:mai will not match a file at src/main/java/Foo.java because the indexed term is main, not mai. Specifically for file names, path:foo will not match src/foo.java — the full filename including extension must be specified, e.g. path:foo.java.
Example query | Results |
|---|---|
| Files with paths containing the segment |
| Files with paths containing the consecutive segments |
| Files which contain the term |
Wildcards for path and repository modifiers
The path: and repo: modifiers support the * and ? wildcards. When a wildcard is used, the pattern is matched against the full file path or repository slug as a single string, not against individual segments of the path or repository slug. * matches any sequence of characters including path separators, and ? matches exactly one character. Wildcard matching is case-sensitive.
Example query | Results |
|---|---|
| Files inside a |
| Files inside a |
| Files named |
| Files named |
| Files in a single-character versioned directory such as |
| Files containing login in any repository whose name starts with |
| Files containing |
| Files containing |
| Files containing |
| Only the repository named exactly |
Language and file extension modifiers
Code search can be restricted to only consider a particular language or a particular file extension. For some languages, adding a language criteria is equivalent to specifying the file extension. For example, lang:go is equivalent to extension:go. For other languages, multiple file extensions are mapped to a single language. For example, the .hs and .lhs file extensions are used for the Haskell programming language, and will be matched when specifying lang:haskell.
Note that 'language' as used here is not related to the Language setting for a repository.
These are the languages recognized by code search:
ada, asp.net, assembly, c, c++, c#, clojure, cobol, cql, css, cython, fortran, go, groovy, haskell, html, java, javascript, js, json, kotlin, latex, less, lisp, markdown, mathematica, matlab, objective-c, ocaml, pascal, perl, php, plain, plsql, properties, python, r, ruby, rust, sas, scala, scss, shell, sieve, soy, sql, swift, typescript, ts, velocity, xml, yaml
Search operators
Search operators can be used with modifiers to refine your search results.
Operators cannot be used alone or with search terms; they can only be used with modifiers.
See more on using multiple modifiers in the next section.
These are the search operators available:
Operator | Example query | Results |
|---|---|---|
|
| Returns files from the |
|
| Returns files from the |
|
| Returns files that contain |
|
| Shorthand for |
Examples of valid and invalid search syntax
Validity | Query | Result |
|---|---|---|
Not valid |
| Operators, such as |
Not valid |
| Operators, such as |
Valid |
| Finds files that contain the terms |
Valid |
| Finds files with the |
Use multiple modifiers
It’s not required to use an operator between modifiers: modifiers are implicitly combined with the AND operator. However, especially when using two modifiers of the same type, you may want to specify an operator like or between them.
For example, here is a query that would find files that 1) are from either repo:A or repo:B 2) have the .js extension 3) have test as part of their file path and 4) that contain the term search-term.
repo:A or repo:B extension:js path:test search-termNote: The example uses the or operator between repo:A and repo:B. Because all modifiers are combined with and by default, the query repo:A repo:B search-term would search for files that are simultaneously in repo A and repo B (which is not possible) and return no results.
Examples of valid and invalid search syntax:
Validity | Query | Result |
|---|---|---|
Valid |
| Finds files with the |
Valid |
| Find all files that contain the term |
Valid |
| Find all files that contain the term |
Valid |
|
|
Valid |
| Finds files with the |
Not valid |
| Looks for files with both the |
Operator precedence and grouping
When you use OR between two modifiers, it applies only to those two modifiers. The implicit AND still joins that pair to the rest of your query. So this query finds files in either the jira or confluence repository that are written in Go:
bitbucket repo:jira or repo:confluence lang:goTo combine more than one or, or to make the grouping explicit, use parentheses.
This query finds files with either the .js or .jsx extension, in either the jira or confluence repository, that contain MyComponent:
MyComponent (repo:jira or repo:confluence) (extension:js or extension:jsx)NOT and - negate the modifier or parenthesized group that immediately follows.
This query will exclude several repositories at once:
MyClass -(repo:jira or repo:confluence)Examples of valid and invalid usage of parentheses:
Validity | Query | Result |
|---|---|---|
Valid |
| Finds files that are in the |
Valid |
| Finds files with the |
Valid |
Note: This is equivalent to writing | Finds files that are not in the |
⚠️ Valid, but not effective |
| Excludes only files that are in both |
Not valid |
Note: Inside parentheses you must use an explicit operator. | Invalid syntax error |
Code search considerations
There are some things to consider regarding how searches are performed:
Search uses the default branch in a repository.
We index files smaller than 512 KB – you won't see search results from larger files.
Wildcard matching in search terms (e.g.
qu?ck buil*) is not supported.Regular expressions are not supported in queries.
Case is not preserved, except in wildcard patterns for
path:andrepo:modifiers.There is no strict query length limit, though very long queries may result in degraded performance.
We make sure that you only see the code you have permission to view in search results.
Search for files
Files can be found by searching their filename or a folder name from its path. See the examples in the table below.
Query | Result |
|---|---|
| Finds files named |
| Finds files that include Note: This type of query will also return code results containing the same keywords. |
| Finds files named |
| Finds files named |
Was this helpful?