LinuxCommandLibrary

git-mv

TLDR

Rename a file

$ git mv [old-name.txt] [new-name.txt]
copy
Move file to directory
$ git mv [file.txt] [directory/]
copy
Force overwrite
$ git mv -f [source] [destination]
copy
Dry run
$ git mv -n [source] [destination]
copy

SYNOPSIS

git mv [options] source destination

DESCRIPTION

git mv moves or renames files and directories while updating the index. It's equivalent to moving the file, deleting the old path from git, and adding the new path.
The command preserves file history by recording the rename. Git detects renames by content similarity, so the explicit command helps ensure proper tracking.
git mv provides tracked file relocation.

PARAMETERS

SOURCE

File or directory to move.
DESTINATION
Target path or directory.
-f, --force
Force move/rename.
-k
Skip errors.
-n, --dry-run
Show what would happen.
-v, --verbose
Report moved files.
--help
Display help information.

CAVEATS

Actually a convenience wrapper. Git detects renames anyway. History follows content, not command.

HISTORY

git mv is a core Git command providing explicit rename/move tracking, though git can detect renames automatically through content analysis.

SEE ALSO

git-rm(1), git-add(1), mv(1)

Copied to clipboard