Convenience wrapper for mv + add + rm of the old name.
Rename or move a tracked file in one step. Equivalent to mv old new && git rm old && git add new, but recorded as a move in the index so rename detection is automatic.
Git doesn't actually track renames. git mv updates the index — adds an entry for the new path with the old blob's SHA, removes the old path. At log/diff time, Git looks for adds and removes with matching content and infers a rename. git mv makes that inference reliable.
git mv [-v] [-f] [-n] [-k] <source> <destination>
git mv [-v] [-f] [-n] [-k] <source>... <destination directory>| Flag | What it does |
|---|---|
-f, --force | Overwrite destination if it exists. |
-n, --dry-run | Show what would happen, do nothing. |
-k | Skip moves that would fail (e.g. source missing). Useful in scripts. |
$ git mv old_name.txt new_name.txt$ git mv parser.c lib/$ git mv -n src/old/ src/new/git mv is just shell convenience. mv + git add -A works identically as far as Git is concerned. Pick whichever fits your muscle memory.git log --follow becomes flaky.core.ignorecase=false to behave.Hit each option, then Check answers. Score is recorded; Next is always open.