---
title: "Deploy to multiple environments with Firebase Hosting"
description: "Deploy to multiple environments with Firebase Hosting"
published: "2016-07-28"
last_updated: "2016-07-28"
authors:
  - "Michael Bleigh (Engineer)"
categories:
  - "Hosting"
  - "Firebase CLI"
  - "Best Practices"
canonical_url: "https://firebase.blog/posts/2016/07/deploy-to-multiple-environments-with"
---

# Deploy to multiple environments with Firebase Hosting

*Published July 28, 2016 by Michael Bleigh (Engineer)*

---
Deploying to production is always a little nerve-wracking. What happens if the new version of the site has bugs you didn’t catch? One-click rollbacks in [Firebase Hosting](https://firebase.google.com/docs/hosting/quickstart) allow you to safely go back the last working version, but how can we ensure that the problem doesn’t happen in the first place?

**The answer is simple**. Test your site in a mirrored production environment. Fortunately for us, the Firebase CLI makes it simple to setup and deploy to multiple environments.

### Adding a new environment 
Adding and switching between environments with the Firebase CLI is as simple as one command: `firebase use`.

When you first initialize your Firebase Hosting project with `firebase init` you specify what project you want to deploy your app to. This is your default project. The `use` command allows you to add another project.

```bash
$ firebase use --add
```

This command prompts you to choose from one of your existing projects:

```bash
$ firebase use --add
$ ? Which project do you want to add? (Use arrow keys)
  my-production-project
> my-staging-project
  my-dev-project
```

Select the project you want to use for a different environment, and then give it an alias. The alias can really be whatever you want, but it’s common to use aliases like “development”, “staging”, or “production”.

```bash
$ firebase use --add
$ ? Which project do you want to add? (Use arrow keys)
  my-production-project
> my-staging-project
  my-dev-project
? What alias do you want to use for this project? (e.g. staging) staging
Created alias staging my-staging-project.
Now using alias staging (my-staging-project)
```

Once you’ve created a new alias, it will be set as the current environment for deployment. Running firebase deploy will deploy your app to that environment.

### Switching environments 
If you want to switch to another environment, just provide the alias in the `use` command.

```bash
$ firebase use default # sets environment to the default alias
$ firebase use staging # sets environment to the staging alias
```

For a single command, you can also specify the environment using the `-P` flag:

```bash
$ firebase deploy -P staging # deploy to staging alias
```

### That’s it! 
That’s all there is to switching environments with Firebase Hosting. If you want a guided tour on getting setup, then [check out our screencast](https://youtu.be/meofoNuK3vo). Let us know what you think in the comments!
