What is git mv?

Why Interviewers Ask This

Foundational questions like this help interviewers calibrate the rest of the interview. A confident, accurate answer signals that you have solid Git & GitHub basics — a prerequisite for any developer role.

Answer

git mv moves or renames a file in both the working directory and the staging area. It is equivalent to running mv old new + git rm old + git add new. Usage: git mv old_name.txt new_name.txt — rename a file; git mv src/utils.js lib/helpers.js — move and rename; git mv src/ lib/ — move an entire directory. Git detects renames heuristically based on content similarity — even if you rename manually with rm + add, Git usually recognizes it as a rename in git log --follow. git log --follow file.txt — show history of a file even across renames (follows the rename). Why it matters: git blame and git log without --follow won't show history before a rename. Rename detection threshold: git diff -M50% — treat as rename if 50%+ content matches. In practice, git mv is mainly useful for explicit rename staging — Git's rename detection works well even with manual moves.

Pro Tip

This topic has Git & GitHub-specific nuances that differ from general programming. Highlighting those nuances in your answer shows expertise rather than generic knowledge.