Renaming a file in Git Bash on Windows
Solution 1
For a git repository, you can use git mv
for renaming/moving files, but only within the same repository. Also avoid doing this on a folder which has been created using git submodule
.
Another option is to create a bash script for rename/move files and then git add
thay again to the repo. Alternatively, you can do this using windows cmd
or create a batch file, just add path to git.exe
to the path
environment variable, if you haven't already done so.
Also, since you are new to using git, I recommend that you use TortoiseGit - this should help you understand what git is.
Solution 2
In Linux, the commands are case sensitive.
mv
is the command you're looking for. It's the shorten for "move", but you can rename files. Like mv oldfilename newfilename
. I think the main problem is that you can't access files on the C:
, D:
etc. drive. Linux has a different directory structure than Windows. There is a root directory (/
), and everything else is mounted to a sub-directory. Like you can access your pendrive on /mnt/pendrive
(just an example, does not work). On Git Bash, the Windows drives are mounted to /c
, /d
etc. So it you want to rename it, you can do like this:
mv /c/somepath/oldfilename /c/somepath/newfilename
posfan12
Updated on June 06, 2022Comments
-
posfan12 almost 2 years
I'm new to Git and Linux/Bash. I have Git Bash installed on Windows 10. How do I rename a file using an absolute path?
For instance the Windows folder path is:
D:\GitHub\Datsville\datsville_inlined
The old file name is:
datsville_rev493_inlined_n_boxed_f.xmpd
The new file name is:
datsville_sf_rev493_inlined_n_boxed_f.xmpd
Bonus: How do I put multiple such commands in a script file? Thanks.