Search in Bitbucket Cloud

To start searching in Bitbucket, click on the magnifying glass under the Bitbucket icon in the sidebar, then enter either a single word or an entire phrase (in double quotes). 

The keyboard shortcut to start a search from anywhere in Bitbucket is "  /  ". Search terms can match the file path, filename, or any content within the file. 

Search results in Bitbucket are code aware, which means your search results are ranked so that function and type definitions will display before other results. You can also use operators or modifiers to help you to refine search results.

Search scopes

The scope of a search changes according to where you are searching from:

Search context

Search scope

An account

All repositories owned or accessible to a user or workspace

Repository

An individual repository and its sub-directories

 

To search in public repositories that aren't associated to any accounts you have access to, go to that repository and search there.

Files can be found just by searching their filename or parts of the path. Using the path in your search only supports exact matches of path segments, but you can search using parts of the filename without a modifier. 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

package.json path:test

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

MyClass

Finds files names MyClass.java and MyClassTest.java

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  (or part of a word), your query would look like this. 

1 "abstract class"

This query would also find instances such as " abstract(class ". 

 The same search query without the double quotes would return files that contain both  abstract and class  in any order.

Search operators

Search operators can be used to refine your search results:

  • Operators must be in ALL CAPS.

  • Operators cannot be used alone; they must be used with an accompanying search term.

  • You cannot use AND in your search query; multiple search terms are implicitly combined. For example, a query for bitbucket jira means that only files that contain both bitbucket and cloud are matched. 

These are the search operators available: 

Operator

Example query

Results

none

bitbucket jira

Returns files that contain the terms bitbucket and jira, in any order

NOT

bitbucket NOT jira

Returns files that contain bitbucket but don't contain jira

-

bitbucket -jira

Used before a term; returns files that contain bitbucket but don't contain jira

Examples of valid () and invalid () search syntax:

Valid

Query

Result

1 MyClass AND MyComponent NOT "YourClass"

AND is not valid syntax; search terms are implicitly combined

1 2 3 4 5 NOT "YourClass"

Operators cannot be used alone; you must specify a search term to match before what to exclude

1 MyClass MyComponent NOT "YourClass"

Finds files that contain the terms MyClass and MyComponent but does not contain YourClass

Search modifiers

Modifiers can be used to refine search results:

  • Use a modifier in the form key:value

  • You can combine multiple modifiers – see the section Use multiple modifiers below.

  • Modifiers can be negated using the NOT operator – see the section search operators above.

These are the search modifiers available:

Modifier

Example query

Results

1 repo:<repo slug> <term>
1 repo:myrepo MyClass

Matches files in myrepo that contain the term MyClass

Wildcards are not supported in repository names

Only the default branch of the repository is searched

1 project:<project key> <term>
1 project:MYPROJ jira

Matches files in the project with key MYPROJ that contain the term jira

1 path:<directory|filename> <term>
1 path:src MyClass

Files with paths matching src which contain the term MyClass

1 ext:<file extension> <term> 
1 ext:lhs jira

Matches Haskell files with the .lhs extension that contain the term jira

1 lang:<language> <term>
1 lang:c jira

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

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.

Example query

Results

1 path:src MyClass

Files with paths matching src which contain the term MyClass

1 path:/src MyClass

Files with paths starting with src which contain the term MyClass

1 path:src/main MyClass

Files with paths matching src/main which contain the term MyClass

1 path:src/*/module MyClass

Files with paths matching src then anything then module which contain the term MyClass

1 path:styles/*.css class

Files with paths matching styles with the extension css which contain the term class. Note that there can be any number of other segments between styles and the filename

1 MyClass NOT path:src

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

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:java is equivalent to ext:java. For other languages, multiple file extensions are mapped to a single language. For example, the .hs.lhs and .hs-boot 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.

Click here to see all the languages recognized by code search...

1 ada asp.net assembly c c++ c# clojure cobol cql css cython fortran go groovy haskell html java
1 javascript 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 velocity xml yaml

Use multiple modifiers

You don't need to use an operator with modifiers because modifiers are implicitly combined depending on their type. When using multiple search modifiers in your search query:

  • Search modifiers of the same kind are implicitly combined.

  • Search modifiers of different kinds are implicitly combined. 

  • Search modifiers apply to the entire search expression.

For example, here is a query that would find files with either the .js or the .jsx extension, that are in either repo A or repo B, and that contain the phrase "search-term".

1 repo:A repo:B ext:js ext:jsx search-term

Examples of valid () and invalid () search syntax:

Valid

Query

Result

ext:js project:myProject MyComponent

Finds files with the js extension that are in the myProject project that contain the term MyComponent .

1 MyClass NOT repo:test

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

1 MyClass -ext:java

Find all files that contain the term MyClass excluding java files

ext:js AND project:myProject MyComponent

AND is not valid syntax; search terms are implicitly combined

ext:js NOT project:myProject MyComponent

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

ext:js ext:java MyComponent

Finds files with the js OR java extension that contain the term MyComponent

Code search considerations

There are some things to consider regarding how searches are performed:

  • Search uses the main branch in a repo.

  • We index files smaller than 320 KB – you won't see search results from larger files.

  • Wildcard searches (e.g. qu?ck buil*) are not supported.

  • We strip the following characters from search terms: !"#$%&'()*+,/;:<=>?@[\]^`{|}~-  

  • Regular expressions are not supported in queries.

  • Case is not preserved (but search operators must be in ALL CAPS).

  • Queries can have up to 9 expressions (i.e. combinations of terms and operators).

  • Queries can be up to 250 characters in length.

  • We make sure that you only see the code you have permission to view in search results.

Last modified on Jun 8, 2021
Cached at 4:13 AM on Oct 21, 2021 |

Additional Help