Skip to main content
Neon Postgres Docs
current

Search documentation

Type to search this documentation.

On this pageOverview

Neon CLI command: git

The git command connects your git workflow to Neon branching. After you install its git hook, switching git branches with git checkout also checks out the Neon branch mapped to that git branch, so you...

The git command connects your git workflow to Neon branching. After you install its git hook, switching git branches with git checkout also checks out the Neon branch mapped to that git branch, so your application code and its database branch stay in sync. Under the hood it delegates to neon checkout and records the git-to-Neon mapping in your local context file.

Before you install the hook, link a Neon project at your repository root with neon link or neon checkout. The hook reads the .neon context file at the repository root, so the project link has to live there.

Subcommands: cleanup, install, status, sync, uninstall

Installs a managed post-checkout git hook that runs neon git sync whenever you switch branches with git checkout. The hook honors your configured git hooks directory and won't overwrite an existing unmanaged post-checkout hook.

The command requires a project already linked at the repository root's own .neon file. If none is linked, install stops and tells you to run neon link or neon checkout <branch> there first.

Bash
neon git install [options]
Bash
neon git install
title="Output"
Git → Neon sync installed. `git checkout <branch>` will now check out the mapped Neon branch.
Hook: /path/to/your/app/.git/hooks/post-checkout

Shows your current git branch, whether the hook is installed, whether sync-on-checkout is enabled, the Neon branch mapped to the current git branch, and all recorded mappings. Use --output json or --output yaml for scripting.

Bash
neon git status [options]
Bash
neon git status
title="Output"
GitBranch         main
HookInstalled     false
FollowOnCheckout  false
MappedNeonBranch  (unmapped — will derive on next sync)
Mappings          (none)

Checks out the Neon branch mapped to the current git branch. This is the command the installed hook runs on every git checkout, and you can also run it by hand. If no mapping exists yet, sync derives a Neon branch name from the current git branch and checks it out, then saves the resulting mapping so later checkouts of that git branch stay stable. The Neon branch has to exist already: sync doesn't create it, so a git branch with no matching Neon branch reports Branch <name> not found. Pass --create to create it. unless a checkout.before hook maps it to an existing branch. A detached HEAD has no git branch, so sync skips it.

Pass --pull to run git pull --ff-only before syncing, so committed files such as migrations match the branch before any checkout.after hook runs. A pull failure warns and sync continues. Pass --no-env-pull to skip pulling the branch's Neon environment variables into a local .env after sync.

Bash
neon git sync [options]
Option Description Type Default Required
--env-pull Pull the branch's Neon env vars into a local .env after sync. On by default. boolean true No
--pull Run git pull --ff-only before syncing so local files (incl. migration files) match the branch before any checkout.after migration runs. Without the flag, prompts when run manually in a TTY and skips in the hook / CI. boolean — No
--quiet Suppress sync's own routine status lines (git pull result, detached HEAD notice). Warnings and the delegated checkout's own output are unaffected. Used by the installed git hook. boolean false No
Bash
neon git sync --no-pull
title="Output"
Checked out branch br-billing-a1b2c3d4 on project polished-snowflake-12345678 (org org-example-12345678). Updated /path/to/your/app/.neon.
Pulled 3 Neon variables into /path/to/your/app/.env.local: DATABASE_URL, DATABASE_URL_UNPOOLED, NEON_BRANCH

Removes git-to-Neon mappings whose local git branch no longer exists. By default it only prunes the mappings. Add --prune-neon-branches to also delete the orphaned Neon branches, which never touches the default or a protected branch. Deleting Neon branches prompts for confirmation unless you pass --yes.

Bash
neon git cleanup [options]
Option Description Type Default Required
--prune-neon-branches Also delete the orphaned Neon branches (never the default or a protected branch). boolean false No
--yes Skip the confirmation prompt before deleting Neon branches. boolean false No

Prune stale mappings only:

Bash
neon git cleanup
title="Output"
Pruned 1 stale mapping(s) from .neon:
  feature/billing → feature/billing
These Neon branch(es) are no longer mapped and were not deleted: feature/billing. Delete them with `neon branches delete <name>`, or run `neon git cleanup --prune-neon-branches` next time before a mapping-only cleanup.

Prune stale mappings and delete their Neon branches without a prompt:

Bash
neon git cleanup --prune-neon-branches --yes

Removes the managed post-checkout hook installed by neon git install and turns off sync-on-checkout. If the post-checkout hook isn't the one Neon manages, uninstall leaves it in place and only clears the sync flag.

Bash
neon git uninstall [options]
Bash
neon git uninstall
title="Output"
Removed the neon git post-checkout hook. Git → Neon sync is off.
Suggest an edit

Propose a replacement for this page. The site team reviews it before applying any changes.

Export
Documentation menu