Home·Terminal commands

git mv

git

Usage

git mv [-f] <source> <destination>

Moves a file and stages the move in one step; git stores no rename, it guesses one from similar content, so a case-only rename needs -f on macOS and Windows.

Common flags

FlagMeaning
-foverwrite the destination
-kskip moves that would fail instead of stopping
-ndry run
-vname each file as it moves

Examples

git mv old.md docs/new.md

moves the file and stages the change in one step

git mv -n src/a.ts src/b.ts

shows what it would do

git mv README.md readme.md

a case-only rename, which needs -f on macOS and Windows

The confusion is that undo has several shapes — moving where a branch points is not the same as adding a commit that reverses it.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does git mv do?

Moves a file and stages the move in one step; git stores no rename, it guesses one from similar content, so a case-only rename needs -f on macOS and Windows.

Q. How do I type it?

git mv [-f] <source> <destination> — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

4 are listed here; the full set is in man git. This command sits under git.

Related commands

man page: man git-mv