Progress:
TIER 1 · MODULE 10· Basics

git mv

Convenience wrapper for mv + add + rm of the old name.

🎯 What & why

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.

🧠 Mental model

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.

🛠️ Synopsis

git mv [-v] [-f] [-n] [-k] <source> <destination>
git mv [-v] [-f] [-n] [-k] <source>... <destination directory>

🎚️ Switches & options

FlagWhat it does
-f, --forceOverwrite destination if it exists.
-n, --dry-runShow what would happen, do nothing.
-kSkip moves that would fail (e.g. source missing). Useful in scripts.

💡 Use cases

🧪 Examples

Rename a file.
$ git mv old_name.txt new_name.txt
Move into a directory.
$ git mv parser.c lib/
Dry-run before doing it for real.
$ git mv -n src/old/ src/new/

🎓 Recommendations

🪤 Common pitfalls

🔗 Related modules

📝 Quiz

Hit each option, then Check answers. Score is recorded; Next is always open.