git mv: Usage, Options & Common CI Errors
git mv renames or moves a file and stages the move in a single step.
git mv is shorthand for mv + git add + git rm of the old path, keeping rename detection clean.
What it does
git mv renames or relocates a tracked file (or directory) on disk and stages both the removal of the old path and the addition of the new one.
Common usage
Terminal
git mv old.txt new.txt
git mv src/ lib/
git mv -f a.txt b.txt # overwrite an existing b.txtOptions
| Flag | What it does |
|---|---|
| -f / --force | Overwrite an existing destination |
| -k | Skip moves that would error, instead of failing |
| -n / --dry-run | Show what would happen |
| -v / --verbose | Report names as they are moved |
Common errors in CI
fatal: destination exists, source=… (use -f to overwrite). fatal: not under version control, source=… means the file is not tracked - git mv only works on tracked paths; add it first or use a plain mv plus git add.
Related guides
git rm: Usage, Options & Common CI Errorsgit rm removes files from the working tree and the index. Reference for --cached, -r, -f, and the "has staged…
git add: Usage, Options & Common CI Errorsgit add stages changes for the next commit. Reference for -A, -p, --update, and the pathspec and ignored-file…
git status: Usage, Options & Common CI Errorsgit status shows staged, unstaged, and untracked changes plus branch state. Reference for -s, --porcelain, -b…
git diff: Usage, Options & Common CI Errorsgit diff shows changes between commits, the index, and the working tree. Reference for --staged, --name-only,…