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

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:myrepo will throw an error.

  • You can combine multiple modifiers; they are combined with AND by default.

These are the search modifiers available:

Modifier

Example query

Results

repo:<repo slug> <term>

Note: You can also use repository: in place of repo:.

repo:myrepo MyClass

 

Matches files in myrepo that contain the term MyClass

  • Wildcards are supported in repository modifiers (see below).

  • Only the default branch of the repository is searched

path:<directory|path segment|filename(with extension)> <term>

path:src MyClass

Files with paths matching src which contain the term MyClass

  • Wildcards are supported in path modifiers (see below)

extension:<file extension> <term>

extension:go jira

Note: do not include the dot delimiter, i.e. extension:.go will not return results.

Matches files with the .go extension that contain the term jira

lang:<language> <term>

Note: You can also use language: in place of lang:

lang:c jira

Matches C files with the .c or .h extensions that contain the term jira

forks:true <term>

Note: forks:true is a top level modifier. It cannot be grouped with other modifiers using and / or or negated using not / -.

forks:true jira

Note: the forks: modifier only accepts the value true.

Matches files from repository forks that contain the term jira.

  • Forks are excluded without this flag.

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

path:src MyClass

Files with paths containing the segment src which contain the term MyClass

path:src/main MyClass

Files with paths containing the consecutive segments src/main which contain the term MyClass

MyClass NOT path:src

Files which contain the term MyClass with paths that do not contain the segment src

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

path:*/src/*/module/* MyClass

Files inside a module/ directory under any subdirectory of src/, which contain the term MyClass.

path:*/styles/*.css class

Files inside a styles/ directory with a .css extension that contain the term class.

path:*/index.?s export

Files named index.js or index.ts preceded by any other path segments that contain the term export

path:index.?s export

Files named index.js or index.ts where index.?s matches the entire path and contains the term export

path:*/v?/* api

Files in a single-character versioned directory such as v1/ or v2/ that contain the term api

repo:mobile-* login

Files containing login in any repository whose name starts with mobile-, such as mobile-ios and mobile-android

repo:*-service login

Files containing login in any repository whose name ends with -service

repo:*payment* login

Files containing login in any repository with payment anywhere in its name

repository:my-repo? login

Files containing login in any repository that starts with my-repo followed by exactly one character, like my-repo1, my-repoX

repo:payment login

Only the repository named exactly payment. Without a wildcard, the name must match in full — this won't match payment-service.

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

AND or and

bitbucket repo:jira AND lang:go

Returns files from the jira repository, written in go, that contain the term bitbucket

OR or or

bitbucket repo:jira or repo:confluence

Returns files from the jira repository or the confluence repository that contain the term bitbucket

NOT or not

bitbucket NOT repo:jira

Returns files that contain bitbucket but exclude results from the jira repository

-

bitbucket -repo:jira

Shorthand for NOT; returns files that contain bitbucket but exclude results from the jira repository

Examples of valid and invalid search syntax

Validity

Query

Result

Not valid

MyClass OR MyComponent AND "YourClass"

Operators, such as OR and AND, cannot be used between search terms.

Not valid

NOT MyClass

Operators, such as NOT, cannot be used with search terms. NOT can only be used to negate modifiers.

Valid

MyClass MyComponent NOT repo:jira

Finds files that contain the terms MyClass and MyComponent, excluding results from the jira repository.

Valid

MyClass (repo:jira or repo:confluence) extension:go

Finds files with the .go extension containing MyClass in either the jira or confluence repository.

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-term

Note: 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

extension:js repo:myRepo MyComponent

Finds files with the js extension that are in the myRepo repository that contain the term MyComponent

Valid

MyClass NOT repo:test

Find all files that contain the term MyClass excluding the test repository

Valid

MyClass -extension:java

Find all files that contain the term MyClass excluding java files

Valid

extension:js AND repo:myRepo MyComponent

AND can be used to explicitly combine modifiers

Valid

extension:js NOT repo:myProject MyComponent

Finds files with the js extension in any project other than myProject that contain the term MyComponent

Not valid

extension:js extension:java MyComponent

Looks for files with both the js AND java extensions that contain the term MyComponent and yields no results.

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:go

To 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

MyComponent (repo:jira or repo:confluence)

Finds files that are in the jira or confluence repositories that contain the term MyComponent

Valid

MyComponent (repo:jira and extension:go)

Finds files with the go extension that are in the jira repository that contain the term MyComponent

Valid

MyClass -(repo:jira or repo:confluence)

Note: This is equivalent to writing MyClass -repo:jira -repo:confluence.

Finds files that are not in the jira or confluence repositories that contain the term MyClass

⚠️ Valid, but not effective

MyClass -(repo:jira and repo:confluence)

Excludes only files that are in both jira and confluence repositories simultaneously, which isn't possible. As a result, nothing is excluded. Use or to exclude both

Not valid

(repo:jira repo:confluence)

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: and repo: 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

package.json

Finds files named package.json

package lock json

Finds files that include package, lock, and json, such as package-lock.json

Note: This type of query will also return code results containing the same keywords.

package.json path:test

Finds files named package.json with a path that contains test

MyClass

Finds files named MyClass.java and MyClassTest.java

 

Still need help?

The Atlassian Community is here for you.