n8n source control: connect Git and set up dev and prod environments
How n8n source control works: connect a Git repo, push and pull workflows between dev and prod, what gets committed, and the new Environments preview.

n8n source control links an n8n instance to a branch in a Git repository so you can push workflows from one instance and pull them into another. That is how n8n builds environments: a development instance and a production instance, each connected to Git, with work flowing one way from dev to prod. It's a paid feature (Business or Enterprise), it needs an instance owner or admin to set it up, and it never sends credential secrets to Git.
The short version:
- Set it up in Settings > Environments: paste the repository URL, add n8n's SSH key as a deploy key with write access (or use a personal access token over HTTPS), pick a branch, and select Save settings.
- Push commits the workflows you select, plus tags, folders, projects, data table schemas and credential and variable stubs. Pull loads them on the other instance and overwrites local changes.
- Edit only on development, push, then pull on production. Turn on Protected instance on production so nobody edits there.
- n8n can't detect conflicts in workflows: whatever you push or pull wins. Keep the flow in one direction.
- You can automate the pull (or the whole promotion) with the public API's
/source-controlendpoints. - A new version called Environments (promote and apply) is in Preview on Enterprise plans; the push and pull feature is now called Environments (Classic).
Who can use source control
The feature availability note in n8n's docs says:
- Source control is available on Business and Enterprise plans.
- Only an instance owner or instance admin can enable and configure it.
- Instance owners and admins can push and pull. Project admins can push but can't pull.
Two sources don't agree with that note on the plan, so check your plan before you count on it: the public API page for environments calls Environments "an Enterprise feature", and the settings page shown to unlicensed instances reads "Available on the Enterprise plan" in the current n8n source. Either way, the free self-hosted Community Edition doesn't include it.
If you're on the Community Edition and just need to copy workflows to another instance, see our guide to moving n8n workflows between instances (JSON, the CLI and n8n packages).
How n8n uses Git
n8n's own docs warn that you shouldn't view its source control as full version control. It uses three Git ideas:
- Push sends your work from the instance to the connected branch. In n8n, commit and push happen in one step.
- Pull loads the workflows, tags and variables from the branch into the instance.
- Commit is one push.
There's no review-and-merge step inside n8n. If you want pull requests, you do them in your Git provider (GitHub, GitLab, Bitbucket and so on), between branches.
An environment in n8n is an instance plus the branch it's connected to. The environments page describes the usual pair: development, where you build and change workflows, and production, where the live workflows run.
Pick a branch pattern
The relationship between instances and branches is up to you. The branch patterns page covers four:
| Pattern | How work moves | Good for |
|---|---|---|
| Multiple instances, one branch | Push from dev, pull on prod | Work is available everywhere as soon as you push; testing a new n8n version on a second instance against the same workflows |
| Multiple instances, multiple branches | Push from dev to its branch, merge into the prod branch in your Git provider, pull on prod | A safety layer (a pull request) before anything reaches production; more than two instances |
| One instance, multiple branches | The owner switches the instance's branch to load different work | Reviewing work pushed by different people |
| One instance, one branch | Push from the instance to its branch | The simplest setup, for example a scheduled backup of the instance to Git |
The trade-off is spelled out in the docs. With one branch, work is in production as soon as someone pulls, so a mistaken push can reach production, especially if pulls are automated. With one branch per environment, a pull request stands between dev and prod, at the cost of more manual steps.
Switching branches on one instance doesn't clean anything up: n8n leaves the workflows from every branch you've loaded on the instance.
Set up source control
1. Create the repository and branches
Create a new repository for n8n and the branches you need, for example development and production. n8n's tutorial adds two practical points: make the repository private unless you want your workflows, tags and variable and credential stubs on the internet, and create it with a README so you can create branches right away.
2. Configure Git in n8n
- Go to Settings > Environments. (On versions that also offer the new Environments, n8n labels this page Environments (Classic).)
- In Git repository URL, enter the SSH URL (
git@github.com:<your-org>/<your-repo>.git) or the HTTPS URL (https://github.com/<your-org>/<your-repo>.git). - For SSH, copy the key n8n shows. n8n supports ED25519 (the default) and RSA; select RSA under SSH Key if your Git host needs it. For HTTPS, enter your Git Username and a personal access token as the Token.
On self-hosted n8n, N8N_SOURCECONTROL_DEFAULT_SSH_KEY_TYPE=rsa makes RSA the default key type (source control variables). More settings like this are in our n8n environment variables guide.
3. Give n8n write access to the repository
- SSH: add n8n's key as a deploy key with write access on the repository.
- HTTPS: the token needs repository read and write access (Contents read/write on GitHub, source code pull/push on GitLab).
If your Git host uses a certificate from a private certificate authority, set GIT_SSL_CAINFO to the path of a PEM file with the CA certificate (or GIT_SSL_CAPATH to a c_rehash directory). This works from n8n 2.40.0. Git uses its own trust store, so n8n's general custom CA setting doesn't apply here, and the file replaces Git's default trust store: include public root certificates too if the instance also talks to public Git hosts.
services:
n8n:
image: docker.n8n.io/n8nio/n8n:<version>
environment:
- N8N_SOURCECONTROL_DEFAULT_SSH_KEY_TYPE=ed25519
- GIT_SSL_CAINFO=/certs/git-ca.pem
volumes:
- ./certs/git-ca.pem:/certs/git-ca.pem:ro4. Connect and choose the branch
- Select Connect.
- Under Instance settings, choose the branch for this instance (Branch connected to this n8n instance).
- On production only, select Protected instance. It prevents editing source-controlled resources on that instance, and n8n blocks pushing from it ("You can't push changes from a protected instance").
- Optionally pick a Color. It shows next to the push and pull buttons so people can tell instances apart.
- Select Save settings.
Repeat on each instance, connecting each to its branch.
Push your work from development
- Select Push in the main menu.
- In Commit and push changes, select the workflows and data tables to push. You can filter by status (new, modified, deleted) and search. n8n adds tags and variable and credential stubs automatically.
- Enter a one-line commit message and select Commit and push.
Two details that catch people out:
- n8n pushes the current saved version of a workflow, not the published one (push and pull). Publishing on the other instance is a separate step.
- Pushing overwrites what's in Git for the selected workflows. Push only the ones you mean to, not everything.
What goes to Git, and what doesn't
| Resource | What n8n commits |
|---|---|
| Workflows | The workflow, its tags and the owner's email address |
| Credentials | A stub: ID, name and type. Other fields only if they're expressions. Never the secret values |
| Variables | A stub: ID and name, no value |
| Data tables | The schema (table name, column names, types and order), no rows |
| Projects and folders | Included |
So after the first pull on a new instance, you fill in every credential and variable value by hand. If you need different credentials per environment, the docs point to external secrets, which keep credentials in an external vault.
Pull the work into production
- Select Pull in the main menu.
- If n8n warns that local changes will be lost, select Pull and override.
- Fill in any new credential or variable stubs n8n tells you about.
On a multi-branch setup, merge the development branch into the production branch in your Git provider first, then pull (copy work between environments).
What else happens on pull, according to the docs:
- Auto-publish. The pull dialog has an Auto-publish setting: Off (default, workflows keep their local publish state), If workflow already published (republish only workflows already published here), or On (try to publish everything, including new workflows). Archived workflows are never published. n8n shows which ones failed, for example because of missing credentials.
- A few seconds of downtime. Pulling a change to a published workflow unpublishes it, pulls, then republishes it.
- Owners can change. n8n keeps the owner if a user with the same email exists on the target; otherwise the user who pulls becomes the owner. Projects are matched by ID, and missing ones are created.
- Deletions are offered, not forced. Workflows, credentials, variables, tags and data tables deleted in Git stay on the instance until you confirm their removal. The exception is data tables: one that exists locally but not in Git is deleted on pull, rows included, and a forced pull (API or automation) does it without asking.
- Data table columns removed in Git are deleted locally with their data. n8n warns in the pull dialog first; it can't be undone.
Conflicts: why work must flow one way
n8n resolves credentials, variables and tags itself, but it can't detect conflicts on workflows. A push overwrites Git with your local copy, and a pull overwrites your local copy with Git. If two people change the same workflow, the last push or pull wins.
On pull, n8n creates tags, variables and credentials that don't exist yet and leaves existing ones alone, with three exceptions: a variable value set through the API or externally overwrites the existing value, a renamed credential takes the name from Git, and a renamed tag is renamed locally.
To check a workflow before pushing or pulling, use the workflow diff icon in the push or pull dialog. It shows both versions with added, modified and deleted nodes and connections, and a JSON diff for each changed node (workflow diffs). The docs list workflow diffs for Business and Enterprise when self-hosted, and Enterprise on n8n Cloud.
Automate the pull with the public API
The public API has three source control endpoints (environments via API); status and push exist from n8n 2.39.0:
| Endpoint | What it does |
|---|---|
GET /api/v1/source-control/status?direction=push (or pull) | Lists pending changes with each file's id, type and status |
POST /api/v1/source-control/push | Commits the files you list in fileNames, with a commitMessage |
POST /api/v1/source-control/pull | Pulls from the connected branch; force and autoPublish (none, published or all) |
A typical CI step after you merge into the production branch:
curl --request POST \
--url "https://<your-prod-instance>/api/v1/source-control/pull" \
--header "Content-Type: application/json" \
--header "X-N8N-API-KEY: $N8N_PROD_API_KEY" \
--data '{"force": true, "autoPublish": "published"}'Scope the keys to enforce direction: sourceControl:read and sourceControl:push on development, sourceControl:read and sourceControl:pull on production. In n8n 3.0 the API key dialog groups these three scopes under Environments. If a selected file has changed both locally and in Git, push without force fails with 409 and lists the conflicts. Our public API guide covers creating keys and the X-N8N-API-KEY header.
The new Environments (Preview)
n8n's docs now call the push and pull feature Environments (Classic) and document a successor, Environments. It's in Preview, available on Enterprise plans (Cloud and self-hosted), and n8n says to try it on test instances first.
Instead of push and pull, you promote changes from an instance to an environment (with Git-based promotion, a branch) and apply them on the target instance, optionally after a promotion review. The comparison page lists the main differences:
- Selected workflows bring their dependencies (credentials, variables, data tables, tags). Variables travel with their values; credential secrets still never do.
- Apply checks for blockers and asks you to confirm destructive changes, where Classic pull overwrites after one confirmation.
- Promotion reviews happen in n8n with a visual diff, based on merge requests n8n opens on GitLab. Other Git hosts work through Generic Git.
- Not supported yet: personal projects, project admins promoting, auto-publish on apply, the instance color, picking dependencies yourself, workflow descriptions, and credential sharing settings.
Classic and Environments store content in Git in different formats, so Apply can't read what Classic pushed; n8n recommends a new repository or an empty branch for the switch. Each instance uses one or the other, and while Environments are in Preview you can switch back from Settings > Environments. Pipelines that call the /source-control endpoints keep running Classic push and pull after an upgrade, and n8n says it plans to block them on instances that use Environments, so move them to the promotion endpoints first.
For most teams today, the stable choice is still Classic push and pull.
Next steps
- Update self-hosted n8n safely: a second instance on one branch is a good way to test a new version before production.
- Move n8n workflows between instances: the options without source control, including n8n packages.
- More operations guides under DevOps.
Sources
- Source control and environments (n8n docs)
- Set up source control (n8n docs)
- Git and n8n (n8n docs)
- Environments in n8n (n8n docs)
- Branch patterns (n8n docs)
- Push and pull (n8n docs)
- Copy work between environments (n8n docs)
- Compare changes with workflow diffs (n8n docs)
- Use environments programmatically with the public API (n8n docs source on GitHub)
- Source control environment variables (n8n docs)
- Environments, Preview (n8n docs source on GitHub)
- Upgrade from Environments (Classic) (n8n docs source on GitHub)
- n8n editor UI strings (n8n source, en.json)
Editorial team
The then8nblog editorial team researches every article from n8n's release notes, documentation and source code, states the n8n version each guide was tested on, and has every post reviewed by a human editor before it goes live.



