LinuxCommandLibrary

git-mv

Move or rename tracked files

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 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.
-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)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community