Using Insomnia Environment Variables and Git Sync for Consistent API Testing
A quick guide to using Insomnia’s environment variables and Git‑synced workspaces so teams can share API collections without duplicating requests.
28 Sept 2026, 09:53 UTC

Problem: Duplicated Requests Across Environments
When testing APIs that run against multiple backends (e.g., Development, Staging, Production), it’s common to copy the same request collection for each environment. This leads to drift: a change made in one copy must be manually reproduced elsewhere, increasing the chance of mismatched headers, URLs, or authentication tokens.
Thesis: Leverage Workspace‑Scoped Variables and Git‑Synced Workspaces
Insomnia lets you define variables at the workspace level and bind them to named environments. By storing the workspace in a Git repository, every change to requests, environments, or plugins becomes a version‑controlled JSON file. The result is a single source of truth that can be switched between environments with a dropdown and shared safely across a team.
How Environment Variables Work
Variables are created in Workspace → Environments. Each environment is a key‑value map; values are referenced anywhere in a request using the double‑curly syntax {{variableName}}. For example, a variable baseUrl set to https://api.dev.example.com can be used in a request URL as {{baseUrl}}/users. Switching the environment dropdown instantly rewrites all references.
Enabling Git Synchronization
In the workspace settings, choose Git → Clone/Push. Provide a Git repository URL (e.g., [contact removed]:team/api‑tests.git) and optionally a branch. Insomnia will:
- Clone the repo into a local folder on first launch.
- On every save, write the updated request/environment files as JSON and push them.
- On startup, pull remote changes to keep the local workspace up‑to‑date.
This requires read/write access to the repository and a network connection. If the repo is private, ensure your SSH key or personal token is configured in the environment where Insomnia runs.
Worked Example: Switching Environments with a Shared Collection
Assume a repository already exists at https://github.com/example/api‑specs and you have push rights.
- Create the workspace: In Insomnia, click New Workspace, name it API‑Specs, and set the Git remote to the URL above.
- Add environments: Open Workspace → Environments, create three environments:
dev,staging,prod. In each, define a variablebaseUrlwith valueshttps://api.dev.example.com,https://api.staging.example.com, andhttps://api.prod.example.comrespectively. - Create a request: New request → GET → URL:
{{baseUrl}}/v1/users. Add an Authorization header that references another variable, e.g.,Bearer {{apiToken}}(defineapiTokenper environment as needed). - Save and verify: After saving, Insomnia pushes the request JSON to the repo. Switch the environment dropdown from
devtostaging; the URL in the request editor updates instantly to reflect the new baseUrl. - Check the repo: In a terminal, run
git pull origin main(or your default branch) inside the cloned folder. You should see files likerequests.jsonandenvironments.jsonupdated with the latest changes. No merge conflict should appear if you are the only editor.
If a teammate edits the same request and pushes, Insomnia will pull their changes on next startup or manual Workspace → Git → Pull. Conflicts appear as standard Git merge conflicts that must be resolved outside Insomnia.
Trade‑offs and Limitations
- Environment variable uniqueness: Duplicate names within an environment silently overwrite each other, which can cause unexpected request behavior. Always verify variable names are unique before saving.
- Binary assets: File uploads or large binary payloads stored directly in requests are persisted as base64 strings in the JSON, bloating the repository. Consider referencing external files or using Insomnia’s
filevariable type only for small test data. - Network reliance: Git sync requires connectivity; offline work will diverge until a push/pull can be performed.
To check that synchronization is working, after making a change:
- Save the request in Insomnia.
- Run
git statusin the repository folder – the relevant JSON file should appear as modified. - Run
git diffto see the exact textual change (e.g., updated URL or header). - Commit and push, then have a teammate pull and confirm the change appears in their Insomnia workspace.
Actionable Closing
Start by converting one of your existing API collections into a Git‑synced workspace:
- Create a bare Git repository for the project.
- In Insomnia, enable Git sync pointing to that repo.
- Define environment variables for each target backend.
- Use the {{variable}} syntax everywhere you need environment‑specific values.
- Train the team to switch environments via the dropdown and to rely on Git for version control.
With this setup, you eliminate request duplication, gain a clear audit trail of API changes, and reduce the risk of running tests against the wrong endpoint.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.