# grit mv

> Rename or move tracked paths.

## Synopsis

```text
grit mv [-f|--force] [--dry-run] <source>... <destination>
```

## Description

Renames or moves tracked paths in the working tree and index, preserving object ids and cached stat data. Pathnames in human and `--markdown` output use the same quoting rules as [`grit status`](https://grit-scm.com/docs/status/index.md) (see **Description** there). The last argument is the destination; earlier arguments are sources.

When the destination is an existing directory, each source is moved into that directory under its original base name. A trailing slash on the destination (`docs/` or `docs//`) is accepted and means the same as naming the directory without the slash. Moving a directory renames the whole tree of tracked files. Multiple sources are validated together before anything moves; the index is updated once.

Grit refuses untracked sources, overwriting an existing destination without `--force`, and moving a directory into one of its own subdirectories.

On case-insensitive volumes with `core.ignorecase=true`, case-only renames succeed: the worktree spelling updates and the index tracks the destination path. That includes renaming a tracked directory to a case-only spelling (for example `Dir` to `dir`), which updates every indexed path under that tree (for example `Dir/x.txt` becomes `dir/x.txt`). Single-file case-only renames behave like `git mv`; upstream Git still fails directory case-only renames on APFS.

When a move leaves a source directory empty, grit leaves that directory on disk (same as `git mv`).

## Options

| Option | Description |
| --- | --- |
| `<source>...` | One or more tracked paths to move. |
| `<destination>` | Final path or existing directory (last argument). |
| `-f`, `--force` | Replace an existing file at the destination. |
| `--dry-run` | List planned renames without changing the index or work tree. |

## Examples

Rename a file:

```console
$ grit mv draft.txt final.txt
Renamed draft.txt -> final.txt.
```

Move into a directory:

```console
$ grit mv report.txt docs/
Renamed report.txt -> docs/report.txt.
```

## JSON output

Live `--json` output follows schema [v2](https://grit-scm.com/docs/mv/schemas/mv/v2.json/index.md). The frozen [v1](https://grit-scm.com/docs/mv/schemas/mv/v1.json/index.md) schema documents the legacy `{from, to}` shape.

Pass `--json` for stable, scripting-friendly output:

| Field | Type | Meaning |
| ----- | ---- | ------- |
| `moves` | array of `{from, to}` | Each rename performed or previewed. |
| `dry_run` | boolean | `true` when `--dry-run` was passed. |

Example:

```json
{
  "dry_run": false,
  "moves": [
    {
      "from": "draft.txt",
      "to": "final.txt"
    }
  ]
}
```

## Markdown output

Schema: [v2](https://grit-scm.com/docs/mv/schemas/mv/v2.json/index.md)
Pass [`--markdown`](https://grit-scm.com/docs/global-options/index.md) for agent-friendly output:

```text
- **moves**:
  - `draft.txt` → `final.txt`
```


## Exit status

| Code | Meaning |
| ---: | --- |
| `0` | Success ([`success`](https://grit-scm.com/docs/exit-codes/index.md)). |
| `1` | Command failed ([`failure`](https://grit-scm.com/docs/exit-codes/index.md)). |
| `2` | Invalid flags or arguments ([`usage`](https://grit-scm.com/docs/exit-codes/index.md)). |

See [Exit codes](https://grit-scm.com/docs/exit-codes/index.md) for shared rules and structured `--json` `kind` values.


## See also

[grit add](https://grit-scm.com/docs/add/index.md), [grit rm](https://grit-scm.com/docs/rm/index.md), [grit status](https://grit-scm.com/docs/status/index.md)
