Ad space (banner)
🌿Git Lessons
Lesson 40 / 59

Recording a Rename with git mv

This lesson covers recording a file rename with git mv. It's for anyone searching "git mv usage."

git mv correctly records a file's rename or move as part of Git's history. Git tracks the change more clearly through this than through renaming with an ordinary file operation.

In Try It, run git mv app.js main.js. The file app.js is renamed to main.js, and that operation is staged in Git.

A common early mistake is renaming a file directly through the OS's file manager — Git may then interpret it as a "deletion" plus a "new file," so using git mv keeps the change history recorded more cleanly.

In real teams, using git mv when reorganizing a project's file structure is the recommended convention, since it lets the rename history be tracked correctly.

Git
Try it (type this into the pseudo terminal)
git mv app.js main.js

🧑‍💻 You can type this command into the Git pseudo terminal to try it yourself (this page itself has no interactive terminal).

Ad space (banner)
Ad space (in-article)