Skip to main content
Bazel has hundreds of command-line flags that control build behavior. Even experts regularly discover flags they didn’t know existed. In this section, you’ll learn how to use flags effectively, and how to manage them using .bazelrc configuration files.

Basic flag syntax

Flags are passed to Bazel commands like any command-line program, using double-hyphens such as this:
To distinguish between flags passed to Bazel itself and arguments passed to a program Bazel runs, or to exclude a target from a target pattern, use a bare — to separate them:
The bare -- marks the boundary where Bazel stops interpreting flags and treats everything that follows as either program arguments or target patterns.

Flag syntax shortcuts

Short form

Some flags have a single-letter short form using a single hyphen:

Flag negation

Boolean flags can be negated by adding no as a prefix:

Managing flags with .bazelrc files

Flags are stored in Unix-style RC files so you don’t have to remember and type them repeatedly. Storing your flag preferences in .bazelrc files allows you to:
  • Set system-wide defaults in /etc/bazel.bazelrc.
  • Share team configurations in .bazelrc at the repository root.
  • Define personal preferences in $HOME/.bazelrc, these preferences apply to all your Bazel repositories.
  • Define personal, project-specific preferences in a user.bazelrc file at the repository root, following Bazel’s recommended best practices.

Writing .bazelrc files

In .bazelrc files, each line begins with a command scope, followed by one or more flags.
The command scope determines which Bazel commands receive the flag.
Applying flags to all commands Use common to apply a flag to all commands that support it:
Grouping flags with —config Flags can be grouped into named configurations and enabled using the —config flag:

Organizing .bazelrc files as projects grow

In a real project, flags get hard to organize, so we recommend that the .bazelrc file in your project imports from several rc files for convenience. Learn more bazelrc-preset. A newly created project includes that preset at the start of the file:
The Bazel flag registry, provides a nice interface for browsing flags, or sending a permalink to your coworker pointing them to a flag.