mv
git mv is a command used to move or rename files and directories in a Git repository. It is a convenient way to perform these operations because it stages the changes for you, so you don't need to run git add after moving or renaming the files.
Basic Usage
Move a File
To move a file from one location to another, use the following command:
git mv old_file_path new_file_pathThis will move the file from
old_file_pathtonew_file_pathand stage the change.Rename a File
To rename a file, use the same command with the new file name:
git mv old_file_name new_file_nameThis will rename the file from
old_file_nametonew_file_nameand stage the change.Move a Directory
To move a directory and all its contents, use the following command:
git mv old_directory_path new_directory_pathThis will move the directory from
old_directory_pathtonew_directory_pathand stage the change.
Examples
Move a File
git mv src/old_file.txt src/new_file.txtThis command moves
old_file.txtfrom thesrcdirectory tonew_file.txtin the same directory.Rename a File
git mv README.md README.txtThis command renames
README.mdtoREADME.txt.Move a Directory
git mv docs/old_directory docs/new_directoryThis command moves the
old_directoryfrom thedocsdirectory tonew_directoryin the same directory.
Using git mv ensures that the changes are tracked correctly by Git and staged for the next commit.