Firebase CLI Deploy Firebase apps

Version 15.33.0 · source

Start here

firebase login
Sign in
firebase init
Set up this folder
firebase use <project>
Pick a project
firebase emulators:start
Run locally
firebase deploy
Ship everything
firebase deploy --only hosting
Ship one service
firebase functions:log
Read logs
firebase projects:list
List projects

Concepts

  1. firebase init firebase.json
  2. Emulators local test
  3. Project live services

Account & Projects

firebase login
Sign in via browser
firebase login --no-localhost
Sign in on a remote machine
Prints a URL; paste the returned code back.
firebase logout
Sign out
firebase projects:list
List your projects
firebase use <project>
Set the active project
firebase use --add
Add a project alias
Aliases land in .firebaserc, e.g. staging and prod.
firebase use <alias>
Switch to an alias
firebase --project <id> <command>
Override project for one run
firebase login:list
List signed-in accounts
firebase open <resource>
Open a console page

Setup

npm install -g firebase-tools
Install the CLI
firebase init
Configure services here
Interactive: pick Hosting, Functions, Firestore, Emulators.
firebase init hosting
Set up one service
firebase apps:list
List registered apps
firebase apps:sdkconfig <platform> <app-id>
Print an app's SDK config

Deploy

firebase deploy
Deploy all configured services
firebase deploy --only hosting
Deploy Hosting only
firebase deploy --only functions
Deploy all functions
firebase deploy --only functions:<name>
Deploy one function
firebase deploy --only firestore:rules
Deploy Firestore rules
firebase deploy --only firestore:indexes
Deploy Firestore indexes
firebase deploy --except functions
Deploy all but one service
firebase deploy --message "<msg>"
Label the release

Hosting

firebase hosting:channel:deploy <channel>
Deploy to a preview channel
Gives a temporary URL; add --expires 7d to set its lifetime.
firebase hosting:channel:list
List preview channels
firebase hosting:channel:delete <channel>
Delete a preview channel
firebase hosting:clone <src>:<ch> <dst>:live
Promote a version to live
firebase serve --only hosting
Serve Hosting locally
firebase hosting:disable
Stop serving Hosting

Functions

firebase functions:log
Show function logs
firebase functions:log --only <name>
Logs of one function
firebase functions:list
List deployed functions
firebase functions:delete <name>
Delete a function
firebase functions:secrets:set <KEY>
Create or update a secret
firebase functions:secrets:access <KEY>
Read a secret value
firebase functions:shell
Invoke functions locally

Emulators & Firestore

firebase emulators:start
Start all emulators
firebase emulators:start --only <list>
Start chosen emulators
Comma-separated, e.g. firestore,auth.
firebase emulators:start --import <dir>
Load saved emulator data
firebase emulators:start --export-on-exit <dir>
Save data on shutdown
firebase emulators:exec "<cmd>"
Run tests against emulators
Starts them, runs the command, shuts them down.
firebase setup:emulators:firestore
Download Firestore emulator
firebase firestore:indexes
List deployed indexes
firebase firestore:delete <path> -r
Delete a document tree
Permanent; add --force to skip the prompt.
firebase firestore:delete --all-collections
Wipe the database
Destroys all data in the project.
firebase database:get <path>
Read Realtime Database data

CI & Config

firebase --token <token> <command>
Authenticate in CI
Deprecated; prefer a service account.
firebase login:ci
Create a CI token
firebase --debug <command>
Verbose output
firebase --non-interactive <command>
Fail instead of prompting
firebase --json <command>
Machine-readable output
firebase help <command>
Help for a command

Recipes

First deploy
firebase loginfirebase initfirebase emulators:startfirebase deploy
Staging and prod aliases
firebase use --add   # pick project, alias stagingfirebase use stagingfirebase deploy --only hostingfirebase use prod
Preview before going live
firebase hosting:channel:deploy pr-42 --expires 3d# share URL, then:firebase deploy --only hosting
Test with emulators in CI
firebase emulators:exec --only firestore \  "npm test"