10 Moving Files in Git

Performing tasks such as reorganizing files, changing file formats, and so on, requires that files and sometimes entire directories get moved. git mv handles this for you.

You provide it with two options: the name of the original file and the new name. This works on files, directories, or symlinks—anything Git can track.

You can move files, directories, and symlinks into other directories as well. Provide git mv a directory as the second option, and you’re set.

Git stages the change for you after you call git mv. You must call git commit after git mv to make the move permanent.

git mv won’t overwrite an existing file; it displays an error instead. You can override this behavior by providing --force

Get Pragmatic Guide to Git 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.