---
title: "Branch-specific environment variable values from the Netlify UI, CLI, or API"
description: "New in Netlify Labs, the beta for scopes and deploy contexts for environment variables now includes the ability to set different values for different branches. Alongside this update, you can now set environment variables for specific deploy contexts with the Netlify CLI or API."
source: "https://www.netlify.com/blog/branch-specific-environment-variable-values-from-the-netlify-ui-cli-or-api/"
last_updated: "2026-07-10T19:16:56.000Z"
---
Teams can [manage scopes and deploy contexts on environment variables](https://www.netlify.com/blog/scopes-and-contextual-values-for-environment-variables/) from the Netlify UI. This beta [in Labs](https://app.netlify.com/user/labs) now includes the ability to set a different value for specific branches!

![image](https://cdn.sanity.io/images/o0o2tn5x/production/460940598d5bc55b8591a2a25f9cba44820eccff-1816x1084.png)

If you prefer to use the Netlify CLI or API to interact with your Sites, the “Scopes and deploy contexts for environment variables” beta has also been updated with support for these workflows.

## Set branch values on environment variables from the UI

Some projects might require special configurations on long-lived branches, such as `staging`. In other cases, you might need to preview site updates that require a specific API token—before those changes land in production.

Developers can now set one environment variable key, with a different value on specific branches:

![image](https://cdn.sanity.io/images/o0o2tn5x/production/98e658ec23d1d4fddcf5b778fb11f908249ee505-1200x812.gif)

With this change, `netlify.toml` configuration or build plugins are no longer needed for branch values. The value for branch staging will be applied to any deploy context initiated from `staging`, including Deploy Previews.

For teams with Sites [opted into the beta](https://docs.netlify.com/netlify-labs/experimental-features/environment-variables/get-started/#opt-in-and-migrate-to-the-new-experience), branch value options are available in Site Settings > Environment Variables, as well as Team Settings > Environment Variables (Pro plan and above). Shared environment variables will apply to all Sites in your Team.

## Manage environment variables using the Netlify CLI or API

The Labs beta has also been updated so that teams can scope environment variables, or set values for specific deploy contexts, from the Netlify CLI or API. This includes the ability to set a branch value.

Starting with Netlify CLI version 11.5.0, developers can use [`--scope` and `--context` flags](https://docs.netlify.com/netlify-labs/experimental-features/environment-variables/cli-and-api/) when reading and writing environment variables with `netlify env` commands. You can also pass the `--context` flag to `netlify build` or `netlify dev`, to emulate a build in the given deploy context. Run `npm i -g netlify-cli` on the command line to install the latest version of the Netlify CLI.

As an example, let’s suppose you want to set a specific value for the `CONTEXTUAL_VAR` key on your staging branch. You can:

-   Run `netlify env:set` with the flag and keyword `--context branch:staging`
-   Check your work using `netlify env:list --context branch:staging`
-   Locally emulate builds from this branch using `netlify dev --context branch:staging`

![image](https://cdn.sanity.io/images/o0o2tn5x/production/949e480fa9780fb67f094fc2be82c06240a931a7-1854x934.png)

Likewise, the Netlify API includes new [Environment Variables endpoints](https://open-api.netlify.com/#tag/environmentVariables), with which you can create, read, update, or delete environment variables. Teams with sites in the beta should use these new endpoints to manage their environment variables, rather than [Site endpoints](https://open-api.netlify.com/#tag/site).

You can learn more about the new API endpoints and CLI updates [in the docs](https://docs.netlify.com/netlify-labs/experimental-features/environment-variables/cli-and-api/).

## Try out the new environment variables experience

This marks the last major update to “Scopes and deploy contexts for environment variables” before the new experience becomes generally available. To take advantage of the new functionality and stronger encryption for secrets now, [enable the beta in Labs](https://app.netlify.com/user/labs) and [migrate your sites](https://docs.netlify.com/netlify-labs/experimental-features/environment-variables/get-started/#opt-in-and-migrate-to-the-new-experience) to the new experience. Please [let us know what feedback you have](https://netlify.qualtrics.com/jfe/form/SV_cHlLLPAwunnWN4G), we always appreciate getting your input!

### Share

-   [X (fka Twitter)](https://twitter.com/intent/tweet?text=Branch-specific environment variable values from the Netlify UI, CLI, or API&url=https://www.netlify.com/blog/branch-specific-environment-variable-values-from-the-netlify-ui-cli-or-api/)
-   [LinkedIn](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fwww.netlify.com%2Fblog%2Fbranch-specific-environment-variable-values-from-the-netlify-ui-cli-or-api%2F)
-   [Facebook](https://www.facebook.com/sharer.php?u=https://www.netlify.com/blog/branch-specific-environment-variable-values-from-the-netlify-ui-cli-or-api/)
-   [Bluesky](https://bsky.app/intent/compose?text=Branch-specific environment variable values from the Netlify UI, CLI, or API+https://www.netlify.com/blog/branch-specific-environment-variable-values-from-the-netlify-ui-cli-or-api/)

* * *

### Tags

-   [changelog](/blog/tags/changelog/)
-   [Build](/blog/tags/Build/)

## Keep reading

![](/_astro/bf247538ceca2433c4060a2570f5799d0111d94c-1200x630_1uReWn.webp)

News & Announcements June 28, 2022

[

### Manage scopes and contextual values for environment variables through the Netlify UI

](/blog/scopes-and-contextual-values-for-environment-variables)

-   ![Profile picture of Melanie Richards](/_astro/d92b724b71fa2bff0982537002856fa4b0614316-512x512_ZCJjrO.webp)
    
    Melanie Richards
    

![](/images/blog-fallback-thumbnail.svg)

Tools & Services July 5, 2021

[

### Easy Access Environment Variables

](/blog/2021/07/05/easy-access-environment-variables)

-   ![Profile picture of Tara Z. Manicsic](/_astro/2ac74d0595066130d59f8c97e61332017cdbcb94-1000x921_ZyTafG.webp)
    
    Tara Z. Manicsic
    

## Recent posts

News & Announcements June 25, 2026

[

### Netlify Functions, designed for Agent Experience

](/blog/netlify-functions-designed-for-agent-experience)

-   ![Profile picture of Eduardo Bouças](/_astro/52958f21e8450baf6d8e60302341a984e220c0cd-512x512_13VDlu.webp)
    
    Eduardo Bouças
    

News & Announcements June 24, 2026

[

### How we measure Netlify’s Agent Experience

](/blog/how-we-measure-netlify-agent-experience)

-   ![Profile picture of Sean Roberts](/_astro/bbf2243f8171dbddd80ab2103622106cef84d125-512x512_Z1d2LKE.webp)
    
    Sean Roberts
    

Guides & Tutorials May 15, 2026

[

### How to build a real-time AI chatbot in minutes with Netlify Agent Runners (no backend)

](/blog/how-to-build-a-real-time-ai-chatbot-in-minutes-with-netlify-agent-runners-no-backend)

-   ![Profile picture of Nahrin Jalal](/_astro/f0e7c8f227a03fe58340c99ef5439d5a896c0733-272x272_Z23kDpD.webp)
    
    Nahrin Jalal
    

![](/_astro/3f255b372fa958df35802666ee33b4609b2d71bd-1200x1586_1VtE2D.webp)

### How do the best dev and marketing teams work together?

[Access the report](https://www.netlify.com/reports/2024-leadership-trend-report/access/)