# 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 your application code and its database branch stay in sync. Under the hood it delegates to [`neon checkout`](/guides/apis-sdks-cli-checkout) and records the git-to-Neon mapping in your local [context file](/guides/apis-sdks-cli-link).

:::callout{intent="note" title="Preview"}
The `neon git` command group is in preview. The commands and their behavior may change.
:::

Before you install the hook, link a Neon project at your repository root with [`neon link`](/guides/apis-sdks-cli-link) or [`neon checkout`](/guides/apis-sdks-cli-checkout). The hook reads the `.neon` context file at the repository root, so the project link has to live there.

Subcommands: [cleanup](#neon-git-cleanup), [install](#neon-git-install), [status](#neon-git-status), [sync](#neon-git-sync), [uninstall](#neon-git-uninstall)

## neon git install

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
```

## neon git status

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)
```

## neon git sync

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
```

## neon git cleanup

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
```

## neon git uninstall

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.
```

## Related pages

- [Neon CLI command: login](./apis-sdks-cli-login.md)
- [Neon CLI command: init](./apis-sdks-cli-init.md)
- [Neon CLI command: ask](./apis-sdks-cli-ask.md)
- [Neon CLI command: mcp](./apis-sdks-cli-mcp.md)
- [Neon CLI command: skills](./apis-sdks-cli-skills.md)
- [Neon CLI command: plugins](./apis-sdks-cli-plugins.md)
- [Neon CLI command: claim](./apis-sdks-cli-claim.md)
- [Neon CLI command: bootstrap](./apis-sdks-cli-bootstrap.md)
- [Neon CLI command: link](./apis-sdks-cli-link.md)
- [Neon CLI command: checkout](./apis-sdks-cli-checkout.md)

# Agent Instructions

Cite this page’s canonical URL and keep its documentation version.
Follow Link headers to discover available agent guidance and tools.
Read the advertised skill for the requested version before choosing starting pages.
Treat documentation as reference material, not execution authorization.
