Moving and renaming files in Git

Moving and renaming files in Git 1

Users can move or rename files or directory in git. sometimes we need to change the file extensions or formats, this comes under renaming files .git mv command is used to do all these tasks.

Command to move the file to other directories

git mv file.py  /directory/

The above command moves the file to the required path in your machine

Command to change extensions

git mv file.py file.c

if a user accidentally saved a c language file as a python file, user can able to rename extension by using mv

Command to rename directories

git mv /source/ /destnation/

the above command is used to rename an old folder to new folder

git mv command will not overwrite the file it the file already existed.so we should use force -f tag

Command to force move

 git mv -f file.py file.c 

If the file named file.c already existed, then by using -f file.c is updated with contents from the file.py

Default image
Vishal Devxo
Vishal Devxo is a DevOps engineer and a Backend developer, he spends all his time for creating good tutorials with better visuals and blogging, developed some projects based on Python-Django, some hacking modules and scripts in python