Synopsis
git mv [-f] [-k] [-n] <source> <destination>
Description
The git mv command renames or moves a tracked file and stages the change. Internally it is equivalent to running mv followed by git add on the new path and git rm on the old. The convenience is that the rename happens in a single atomic step that is unambiguously staged.
Note: Git does not actually store renames as first-class operations. Instead, it detects renames by comparing file content similarity at diff and log time. So whether you use git mv or plain mv + git add + git rm, the resulting commit is identical, and rename detection works the same way.
In day-to-day use, git mv integrates closely with shell aliases, editor plugins, and continuous integration. Power users often add aliases that combine flags they always pass, or wrap the command in scripts that enforce team conventions. Output formatting can be customized via Git config — pretty formats, color schemes, and pager behavior are all tunable. When something goes wrong, the first diagnostic step is usually to re-run the command with GIT_TRACE=1 in the environment, which reveals the underlying plumbing calls. For unusual situations, the --help output (git mv --help) opens the full manual page with details on every option, including those rarely used in casual workflows but essential for debugging or scripting at scale.
Understanding how git mv interacts with the rest of Git's data model — the object database, the index, refs, and the working tree — pays dividends. Each command operates on some subset of these pieces, and knowing which it touches helps predict outcomes and recover from mistakes. Reading the official Git documentation alongside hands-on practice in a throwaway repository is the fastest way to internalize the nuances. Most production issues with Git stem from one of three causes: surprising default behavior, partial network operations, or rewriting history that was already shared. A working mental model of git mv's side effects helps avoid all three.
Common Options
| Option | Description |
|---|---|
-f, --force | Overwrite the destination if it exists. |
-k | Skip move/rename actions that would fail without an error. |
-n, --dry-run | Show what would happen without doing it. |
-v, --verbose | Report names of files moved. |
Examples
git mv old-name.txt new-name.txt
# Rename a file in one step
git mv src/utils.js src/lib/utils.js
# Move a file into a new directory (it must already exist)
git mv -n *.md docs/
# Preview moving all markdown files into docs/
git mv -f draft.md final.md
# Force overwrite if final.md already exists
Common Mistakes
If you rename a file outside of Git (with your editor or mv), Git's rename detection still usually works at diff time — but you must run git add -A to stage both the deletion and the addition. Another issue: case-only renames on case-insensitive filesystems (macOS, Windows) require git mv -f or a two-step rename through a temporary name.
Related Commands
git add, git rm, git log --follow