swapenv is a command-line tool designed to simplify the management of .env files that vary per environment. You can create, list and switch between different .env files which are associated with your git branches. Switching git branches will automatically create a copy of your .env file for that branch.
Managing multiple .env files for different environments can be error-prone and time-consuming. swapenv centralizes and automates this process by associating .env files with git branches. With swapenv, you can:
- Quickly switch environments: Easily toggle between different .env files.
- Keep environments organized: Create, list, and remove envs as needed.
- Switch envs with git: Automatically switch envs by changing git branches.
go install github.com/eriicafes/swapenv@latestswapenv provides several commands to manage your .env files. Below is a brief overview of the available commands:
You can also use it as a git subcommand
git envafter initialization.
Manage .env files locally. Create and swap between .env files
Usage:
swapenv [command]
Available Commands:
commit Commit .env file contents to the current env
create Create new env preset
help Help about any command
init Initialize swapenv
list List all envs
rm Remove env
show Show the current env
use Switch env
Flags:
-h, --help help for swapenv
-v, --version version for swapenv
Use "swapenv [command] --help" for more information about a command.Initializes swapenv in your project by creating necessary configuration files, git hook and git subcommand.
swapenv stores its data in the .git/envs directory of your project.
swapenv initAfter initialization you can also use swapenv as a git subcommand.
git env versionCreates a new env using the .env file or a base env.
swapenv create dev
# create and use a new env in one command.
swapenv create dev -uDisplays all available envs.
swapenv ls
# list and switch env in interactive mode
swapenv ls -iSwitches the .env file contents to one of the available envs.
swapenv use dev
# switch env creating it if it doesn't already exist
swapenv use dev -bDisplays the contents of the current env.
swapenv show dev
# show without any arguments will display the name of the current env
swapenv showCommits the .env file contents to the current env, ensuring that any changes are immediately saved.
swapenvautomatically commits the env before switching so commit is not necessary.
swapenv commitRemoves existing envs.
swapenv rm dev
# remove multiple envs
swapenv rm prod stagingTo update swapenv, reinstall it using go install, which will override the existing binary:
go install github.com/eriicafes/swapenv@latestTo remove swapenv, delete the installed binary:
rm $(which swapenv)