Skip to content

Developers

Env Merge

Env Merge

Beta

Merge a base .env file with an overlay .env file, choose which side wins when a key differs, and download one merged .env. Runs in your browser; the files are not uploaded.

  • Free, no sign-up
  • Updated
  • Reviewed by Olgun Ozoktas
Base (A)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Overlay (B)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

When a key has different values, the overlay value is used. This is how most tools layer .env.local over .env.

Add a base file and an overlay, then press Merge

Paste or drop the base .env on the left and the file whose values should be layered on top on the right, for example .env and .env.local. Load sample shows two conflicts and an empty override.

Runs in your browser; the files are not uploaded. Analytics and ads may load on the page.

Why Use Env Merge?

Layering environment files is a daily chore: a shared .env with a personal .env.local on top, a template filled in with a teammate's values, or a staging file patched with a few production settings. Copying keys across by hand drops one sooner or later, and a quick shell loop does not tell you which values it overwrote. Env Merge takes a base file and an overlay, keeps every key from both, applies the conflict rule you pick, and shows each conflict with the value that won, so the merged file holds no surprises.

Env Merge combines two dotenv files into one. Both files are read with the dotenv rules: blank lines and # comment lines are skipped, a leading export is removed, quotes are unwrapped, backslash escapes are decoded inside double quotes, a double-quoted value may span several lines, and an inline # comment after an unquoted value is cut off. A key defined twice in one file keeps its last value, and a warning names the lines.

Every key from both files ends up in the output. A key found only in the base or only in the overlay is copied as it is. A key found in both with the same value is written once. A key found in both with different values is a conflict, and the rule you choose decides it: Overlay wins takes the overlay value, Base wins keeps the base value, Overlay wins unless its value is empty keeps the base value when the overlay leaves the key empty, and Stop and list the conflicts merges nothing and names the keys instead. Every conflict is listed with both values and the one that was used; secret-looking values in that table are hidden by default.

The merged file follows the base key order, with overlay-only keys appended at the end, or is sorted alphabetically when you ask. Values are written unquoted when they can be and in double quotes with escapes when they must be, and export can be written before every line. Comments are not carried over, and the page says so when either file had them. Env Merge does not expand ${VAR} references and does not sync with any secrets manager. To see every difference between two files first, use Env Diff; to check the merged file, use Env Linter.

How it compares

Merging by hand or with a shell loop such as cat .env .env.local works only if the program that reads the result lets the last line win, and it never tells you which values were overwritten. Env Merge writes each key once, applies the rule you picked, and lists every conflict. It parses both files in your browser instead of posting them to a server, and converts nothing else: for JSON or YAML output use the Env JSON Converter or the Env YAML Converter.

Tips for Merging .env Files

  • The output keeps the base file's key order and appends keys that exist only in the overlay at the end, in the overlay's order. Turn on Sort keys A to Z for an alphabetical file instead.
  • Comments and blank lines are not carried into the merged file. Keep the commented original if you need its notes.
  • Values are written unquoted unless they need quotes: a value with a space, a #, a quote, a backslash or a line break is written in double quotes with escapes.
  • Choose Stop and list the conflicts to see every disagreement first, then pick a rule once you know what will be overwritten.
  • To see every difference between the two files, not only conflicts, use Env Diff.

Frequently Asked Questions

How do I merge two .env files?

Paste or drop the base file into Base (A) and the overlay into Overlay (B), pick a conflict rule, and press Merge. The merged file appears with counts, a list of conflicts and the value used for each, and a button to download it as merged.env.

Which value wins when both files define the same key?

The one your rule picks. Overlay wins is the default and uses the overlay value. Base wins keeps the base value. Overlay wins unless its value is empty keeps the base value when the overlay value is empty. Stop and list the conflicts merges nothing and names every key with different values. A key with the same value in both files is not a conflict.

In what order are the keys written?

In the base file's order, with keys that exist only in the overlay appended at the end in the overlay's order. Turn on Sort keys A to Z to write them alphabetically instead.

Are comments kept?

No. Comments and blank lines are not carried into the merged file, and a warning appears when either file had comments. Keep the original files if you need their notes.

How are values quoted in the output?

A value is written unquoted when it can be. A value containing whitespace, a #, a quote, a backslash or a line break, or with leading or trailing spaces, is written in double quotes, with backslashes, quotes, line breaks and tabs escaped.

What if the overlay file is empty?

The base is written out on its own, in the same normalized KEY=value form. The base file cannot be empty; the page asks for one.

Does it expand $VAR or ${VAR} references?

No. Values are copied exactly as written, references included. Nothing is executed.

Are my .env files uploaded?

No. Both files are parsed and merged in your browser, and the text is not sent in any request. Analytics and ads may load on the page as on the rest of the site. There is no API version of this tool on purpose, because .env files usually hold secrets.

Can the output start every line with export?

Yes. Turn on Write export before each line to get a file a shell can source. An export prefix in the input files is always accepted and removed while reading.

Rate This Tool

0/1000

Get Weekly Tools

Suggest a Tool