git mv command is used to move or rename files within a Git repository. It’s a more convenient way to move or rename files compared to manually deleting and adding files. This command also helps in tracking the history of file movements and naming alterations.
git mv <old-file-path> <new-file-path>
1. Moving a File
To move a file from one location to another, use the
git mv command like this:
git mv source_filepath destination_filepath
This will move the
file.txt from the
source directory to the
2. Renaming a File
To rename a file, simply use the
git mv command with the old and new file names:
git mv old-name.txt new-name.txt
It is essential to commit the changes after using
git mvto ensure that the file moves and renames are properly tracked in the Git history.
Renaming or moving files with
git mvpreserves the file’s history and is especially useful in collaborative development to maintain a clear and organized project structure.
git mvcommand can also be used with wildcards or regular expressions to move or rename multiple files simultaneously.
- Anonymous contributorAnonymous contributor14 total contributions
- Anonymous contributor