7

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.

phd
  • 82,685
  • 13
  • 120
  • 165
posfan12
  • 2,541
  • 8
  • 35
  • 57

5 Answers5

7

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
CoderCharmander
  • 1,862
  • 10
  • 18
2

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.

mr NAE
  • 3,144
  • 1
  • 15
  • 35
0

This does not use git bash but if you want to use the linux "rename" command you can download Windows Subsystem for Linux (WSL) 2 here https://learn.microsoft.com/en-us/windows/wsl/install

Jake
  • 683
  • 6
  • 5
0

using command: git mv oldfilename newfilename. once done, you will see file renamed in "git status" output.

-1

Use mv command in windows

As mentioned in above answer, mv command can be used in windows as well to rename the filename. I tried rename and ren commands s suggested, but I was getting error: bash: ren: command not found.

Use below to change the filename:

mv filename new_filename

Alisha Raju
  • 726
  • 6
  • 12