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
| Flag | Meaning |
|---|---|
| -f | overwrite the destination |
| -k | skip moves that would fail instead of stopping |
| -n | dry run |
| -v | name each file as it moves |
Examples
git mv old.md docs/new.mdmoves the file and stages the change in one step
git mv -n src/a.ts src/b.tsshows what it would do
git mv README.md readme.mda 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