Skip to content

Firebase CLI — Command-Line Tools for Deploying and Managing Firebase Projects

DodaTech Updated 2026-06-28 3 min read

In this tutorial, you will learn about Firebase CLI. We cover key concepts, practical examples, and best practices to help you master this topic.

The Firebase CLI provides command-line tools for deploying hosting, managing Cloud Functions, updating Firestore security rules and indexes, and automating Firebase project workflows.

What You'll Learn

  • Installing and configuring the Firebase CLI
  • Deploying hosting, functions, and rules
  • Automating deployments in CI/CD

Why It Matters

The CLI enables repeatable, automated Firebase management. Manual console configuration does not scale. DodaTech uses Firebase CLI in its CI/CD pipeline for automated deployments.

flowchart LR
    A["Firebase CLI"] --> B["firebase init"]
    A --> C["firebase deploy"]
    A --> D["firebase serve"]
    A --> E["firebase functions:shell"]
    B --> F["Configure project"]
    C --> G["Deploy hosting, functions, rules"]
    D --> H["Local emulation"]
    E --> I["Test functions locally"]

Code Examples

# Install Firebase CLI
npm install -g firebase-tools

# Login and initialize
firebase login
firebase init

# Deploy specific services
firebase deploy --only hosting
firebase deploy --only functions
firebase deploy --only firestore:rules
firebase deploy --only firestore:indexes

# Deploy everything
firebase deploy

# Local emulation
firebase emulators:start

# Run functions shell for testing
firebase functions:shell
# CI/CD deployment script
# .github/workflows/deploy.yml
name: Deploy to Firebase

on:
  push:
    branches: [main]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
      - run: npm ci
      - run: npm run build
      - uses: FirebaseExtended/action-hosting-deploy@v0
        with:
          repoToken: '${{ secrets.GITHUB_TOKEN }}'
          firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT }}'
          channelId: live
// firebase.json configuration
{
  "firestore": {
    "rules": "firestore.rules",
    "indexes": "firestore.indexes.json"
  },
  "functions": {
    "source": "functions",
    "runtime": "nodejs18"
  },
  "hosting": {
    "public": "build",
    "ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
    "rewrites": [
      {"source": "**", "destination": "/index.html"}
    ]
  },
  "storage": {
    "rules": "storage.rules"
  }
}
# Manage multiple projects
firebase use --add
firebase use default  # or staging, production
firebase deploy --project staging

Common Mistakes

1. Forgetting to Run firebase init in a New Project

The init command creates the firebase.json configuration file.

2. Deploying Without Building First

Always run the build command before firebase deploy --only hosting.

3. Using Default firebase.json Without Customization

Configure rewrites, headers, and redirects in firebase.json for production.

4. Not Using .firebaserc for Multiple Environments

The .firebaserc file manages project aliases for dev, staging, and production.

5. Ignoring firebase deploy --only for Targeted Deployments

Full deployments take longer. Deploy only changed services when possible.

Practice Questions

  1. What command initializes Firebase in a project directory?
  2. How do you deploy only Cloud Functions?
  3. What does firebase emulators:start do?
  4. How do you set up multiple deployment environments?
  5. What file configures Firebase services?

Answers:

  1. firebase init.
  2. firebase deploy --only functions.
  3. It starts local emulators for Firestore, Functions, Auth, and other services.
  4. Use .firebaserc to define project aliases.
  5. firebase.json.

Challenge: Set up a Firebase project with CI/CD deployment using GitHub Actions. Configure the pipeline to deploy hosting, functions, and Firestore rules on every push to the main branch. Add a preview deployment for pull requests.

FAQ

Can I use the Firebase CLI without Node.js?

The Firebase CLI requires Node.js. Install Node.js first, then install firebase-tools via npm. There is no standalone binary.

How do I authenticate the Firebase CLI in CI/CD?

Use firebase login:ci to generate a CI token, then store it as a GitHub secret. Alternatively, use service account credentials.

What is the difference between firebase serve and firebase emulators:start?

firebase serve is deprecated. Use firebase emulators:start for local development with emulators for all Firebase services.

Can I roll back a deployment with the Firebase CLI?

Yes. Use firebase hosting:clone to copy a previous version or firebase deploy with a tag for rollbacks.

How do I view deployment history?

Run firebase hosting:list to see recent deployments. The Firebase Console also shows deployment history under Hosting.

Mini Project

Create a deployment workflow: initialize a Firebase project with Hosting, Functions, and Firestore. Configure .firebaserc for dev, staging, and production environments. Write deployment scripts for each environment. Set up GitHub Actions for automated deployments with preview channels for PRs.

What's Next

Learn about the Firestore data model to design your database schema, then explore Firestore queries for data retrieval.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro