Name

mv

Synopsis

git mv oldfile newfile
git mv oldfiles ... newdir

Rename oldfile to newfile or move a series of oldfiles into the directory newdir, which must already exist. git mv updates both the work tree and the index.

Tip

There is no need for a git cp (copy) command. Just copy the file using Unix cp and git add. Git is still able to track the history of files moved and copied in this way.

Options

-f (overwrite even if newfile exists)
-n, --dry-run

Examples

To rename file1.c to file1b.c:

$ git mv file1.c file1b.c

To move file1.c and file2.c into the mylib directory:

$ git mv file1.c file2.c mylib/

Get Linux in a Nutshell, 6th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.