We use the
git mv command in git to rename and move files. We only use the command for convenience. It does not rename or move the actual file, but rather deletes the existing file and creates a new file with a new name or in another folder.
We can use the
mv command in git as follows:
git mv options oldFilename newFilename
oldFilename: The name of the file that we rename
newFilename: The new name of the file
git mv filename foldername
filename: The name of the file that is moved
foldername: The name of the folder where the file is moved
The options we can use with the
mv command are:
Consider the code snippet below which demonstrates the use of the
git mv file1.txt file2.txt git commit -m "file1.txt renamed to file2.txt"
The code snippet above renames the file
file2.txt using the
mv command. The
mv command does not rename the file. It deletes the file
file1.txt and creates a new file
file2.txt that has the same contents as
file1.txt. This means that the code is just a shorthand for the code:
mv file1.txt file2.txt git add file2.txt git rm file1.txt
commit command is used in line 3 to save the changes of renamed file to the local repository.
View all Courses