17

Is there a way to change the root (/) directory of git bash on windows.

By default it is set to the installation folder. Setting it to c:\ instead would save needing to type the drive letter e.g. /c/some/path on all absolute paths.

max630
  • 8,762
  • 3
  • 30
  • 55
79E09796
  • 2,120
  • 1
  • 20
  • 33
  • Even if this was possible it would make both `"C:\D\"` and `"D:\"` correspond to same `/D/` – max630 Sep 01 '16 at 09:59
  • It could perhaps add a mount 'drives', so you could do /drives/d. In android its /storage/sdcard0, etc. Which gives the root as / but also access to other drives. – 79E09796 Sep 01 '16 at 10:18

6 Answers6

14

echo 'cd /c/' >> ~/.bashrc

Automatically go to /c/ directory when opening bash cli.

agilob
  • 6,082
  • 3
  • 33
  • 49
  • Why was this downvoted? I upvoted it. It works great for me and is *way* better than copying folders into the root C: drive like the accepted answer suggests. – EverPresent Nov 22 '17 at 21:18
  • If it helps your use case it's great, I wouldn't downvote it. However it doesn't allow unix style absolute paths for the c drive, so can't accept it as the answer either. – 79E09796 Apr 21 '18 at 12:05
3

What you can do is mount some windows paths to a root-based msys2 paths:

mount c:/src /src

Then you can access C:/src/... as /src/...

max630
  • 8,762
  • 3
  • 30
  • 55
  • This is a good workaround, it's limited to mapping individual directories in Cygwin, but something that works in git bash for all directories might not be possible. – 79E09796 Sep 01 '16 at 10:23
  • Right, mounting to root does not work. But I did not propose it. – max630 Jul 20 '17 at 05:42
2

If you installed git right, then two commands will appear in the file explorer menu when you call it with right-click. You will see nice color-full icons for both two commands: - Git GUI Here - Git bash Here took me 3 days... so you can run both from anywhere.. just go there and run from there!!

enter image description here

Andr
  • 88
  • 1
  • 10
1

What worked for me (Windows 10) was to edit the shortcut.

Previously the Target was "C:\Program Files\Git\git-bash.exe" --cd-to-home Start in: was my homedir

I changed Start in to be C: and removed --cd-to-home

Now bash starts in /c

Jim Davis
  • 1,773
  • 1
  • 10
  • 11
1

In your .bashrc file :

function cd {
  cd "/c/${1}"
}

I would think this should work for all cases. This would limit you to C Drive absolute paths though.

yaas
  • 144
  • 2
  • 7
0

I fixed it by searching the bash.rc file in my file explorer, opening the file with code and replacing everything with cd /C:\Users\windows/

aalbagarcia
  • 1,019
  • 7
  • 20
yes
  • 1