# Git Mv: rename a tracked file

Published: 2026-11-30

Rights: original
Source: https://kairos-2z6s.onrender.com/res/git-mv-full-en
`git mv OLD NEW` renames the file and stages the rename in one step. Tested here: git mv renames a file and the rename is staged.

Each command below is the exact command that was run and each output block is copied from the recorded log. Test ids, log hashes and exit statuses are in the evidence table.

(Test: 3 tests were run, TE-80-A, TE-80-B and TE-80-C. The expected non-zero exit is TE-80-C (exit status 128). Every row has a recorded log, and the exit statuses and log hashes are in the evidence table.)

### TE-80-A: git mv renames a file and the rename is staged

Setup for this run, inside a throwaway directory (`mktemp -d`):

```bash
git init -q .
git symbolic-ref HEAD refs/heads/main
git config user.email test@example.invalid
git config user.name tester
git config commit.gpgsign false
printf 'a\n' > old.txt; git add old.txt; git commit -qm one
```

Command:

```bash
git mv old.txt new.txt; ls; git status --porcelain
```

Recorded output:

```
new.txt
R  old.txt -> new.txt
```

Exit status: 0. The output matches the expected text written before the run.

### TE-80-B: git mv into an existing directory keeps the file name and stages the rename

Setup for this run, inside a throwaway directory (`mktemp -d`):

```bash
git init -q .
git symbolic-ref HEAD refs/heads/main
git config user.email test@example.invalid
git config user.name tester
git config commit.gpgsign false
printf 'a\n' > old.txt; git add old.txt; git commit -qm one
mkdir sub
```

Command:

```bash
git mv old.txt sub/; git status --porcelain
```

Recorded output:

```
R  old.txt -> sub/old.txt
```

Exit status: 0. This status and the output match what was written before the run.

### TE-80-C: expected non-zero exit: git mv of a path that does not exist stops with a fatal error

Setup for this run, inside a throwaway directory (`mktemp -d`):

```bash
git init -q .
git symbolic-ref HEAD refs/heads/main
git config user.email test@example.invalid
git config user.name tester
git config commit.gpgsign false
printf 'a\n' > f.txt; git add f.txt; git commit -qm one
```

Command:

```bash
git mv nosuch.txt x.txt
```

Recorded output: none, standard output was empty.

Standard error from the same run:

```
fatal: bad source, source=nosuch.txt, destination=x.txt
```

Exit status: 128. This status and the output match what was written before the run.

TE-80-B: by the setup, sub is an existing directory. git mv old.txt sub/ kept the file name, and the status line reads R  old.txt -> sub/old.txt. TE-80-C: git mv nosuch.txt x.txt exited with status 128, and standard error reads fatal: bad source, source=nosuch.txt, destination=x.txt.

## Limits

The run shows the status view only. Not tested on this page: `-v` (verbose output), `-n` (dry run), `-f` (force the move or rename even when the target exists), `-k` (skip move and rename errors) and `--sparse` (allow updating entries outside the sparse-checkout cone). These option names and descriptions come from the usage text printed by `git mv -h` in git 2.34.1. No run here used any of them.

## Source

- https://git-scm.com/docs/git-mv

## Evidence table

| Test | What it checks | Exit | Verdict | Log sha256 (first 12) |
|---|---|---|---|---|
| `TE-80-A` | git mv renames a file and the rename is staged | 0 | PASS | `0ad2a1c76572` |
| `TE-80-B` | git mv into an existing directory keeps the file name and stages the rename | 0 | PASS | `a8f16c44d3c8` |
| `TE-80-C` | expected non-zero exit: git mv of a path that does not exist stops with a fatal error | 128 | PASS | `b75950e4567f` |

Recorded on: bash 5.1.16(1)-release; git version 2.34.1; Python 3.10.12. Locale C.UTF-8, TZ=UTC.
Every row has a recorded log holding the setup commands, the command, stdout, stderr and exit status. The first 12 characters of the log's sha256 are in the table.

## Related guides
- [Git Describe: name a commit from the nearest tag](https://kairos-2z6s.onrender.com/res/git-describe-full-en)
- [Git Rm Cached: stop tracking a file and keep it on disk](https://kairos-2z6s.onrender.com/res/git-rm-cached-full-en)
- [Git Reflog: the history of where HEAD pointed](https://kairos-2z6s.onrender.com/res/git-reflog-full-en)
- [Git Ls Files: list what Git tracks](https://kairos-2z6s.onrender.com/res/git-ls-files-full-en)
- [git remote: connect a repository to another one](https://kairos-2z6s.onrender.com/res/git-remote-full-en)
