git-mv

Move or rename tracked files

TLDR

Rename a file
$ git mv [old-name.txt] [new-name.txt]
Move file to directory
$ git mv [file.txt] [directory/]
Force overwrite
$ git mv -f [source] [destination]
Move multiple files to a directory
$ git mv [file1.txt] [file2.txt] [directory/]
Dry run
$ git mv -n [source] [destination]

SYNOPSIS

git mv [options] source destinationgit mv [options] source... destination-directory

DESCRIPTION

git mv moves or renames files and directories while updating the Git index. It is equivalent to moving the file with `mv`, deleting the old path with `git rm`, and adding the new path with `git add`.Using this command ensures the rename is properly staged for the next commit. While Git can detect renames automatically through content analysis, using `git mv` makes the intent explicit and updates the index in one step.

PARAMETERS

SOURCE

File or directory to move.
DESTINATION
Target path or directory.
-f, --force
Force move/rename even if the destination exists.
-k
Skip move or rename actions that would lead to an error condition.
-n, --dry-run
Show what would happen.
-v, --verbose
Report moved files.
--help
Display help information.

INSTALL

sudo apt install git
sudo dnf install git
sudo pacman -S git
sudo apk add git
sudo zypper install git
brew install git
nix profile install nixpkgs#git

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)