- Developers who already know basic commit and branch actions
- Readers who want to understand command boundaries and risk
Command Reference
git mv
Rename or move tracked files while keeping the index in sync, which makes large refactors easier to stage consistently.
- A basic mental model of worktree, index, and commits
- Comfort reading `git status` and a small commit graph
- Using local cleanup commands on already shared history
- Continuing to rewrite before confirming a recovery path
git mv renames or moves a tracked file and stages that path change at the same time.
Common examples
git mv old-name.ts new-name.ts
git mv docs/guide.md docs/intro.md
When it helps most
- during rename-heavy refactors
- when you want file movement and staging to happen in one step
How to think about it
Git still reasons primarily about content plus paths. git mv is mainly a convenience command that keeps your working tree and index aligned cleanly.
Useful reminder
Git can often infer renames even if you use your shell mv first. The main value of git mv is clarity and staging convenience.
What problem this command solves in a workflow
git mv renames or moves a tracked file and stages the path change in one step. It keeps the working tree and index aligned, which is especially useful during rename-heavy refactors where you want file movement and staging to happen atomically.
Typical use cases
- Rename tracked files during large refactors so the path change is immediately staged.
- Move files between directories while keeping Git aware of the rename in a single operation.
- Use
git mv --cachedwhen you want to update the index path without touching the working tree filesystem.
Diagram view
Tracked file pathNew destination pathIndex state
Renamed file on diskStaged rename in indexUpdated working tree
Git can often infer renames even after a plain `mv`, but `git mv` makes the intent explicit and stages immediately.
Special cases and boundaries
git mvonly works on tracked files; untracked files must be moved with the shellmvfirst.- Git's rename detection means a shell
mvfollowed bygit addoften produces the same result, sogit mvis mainly a convenience. - If the destination file already exists,
git mvwill refuse unless you force it, to avoid accidental overwrites. - Uncommitted edits in a file being moved are carried along with the rename — the content does not change, only the path.