Changing the root directory (/) of git bash
Asked Answered
A

7

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.

Artima answered 30/8, 2016 at 15:50 Comment(2)
Even if this was possible it would make both "C:\D\" and "D:\" correspond to same /D/Particiaparticipant
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.Artima
E
14

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

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

Elyn answered 31/8, 2016 at 14:26 Comment(2)
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.Fluter
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.Artima
P
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/...

Particiaparticipant answered 1/9, 2016 at 10:8 Comment(2)
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.Artima
Right, mounting to root does not work. But I did not propose it.Particiaparticipant
R
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

Relate answered 18/4, 2018 at 14:22 Comment(0)
F
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

Ferdelance answered 18/10, 2018 at 1:27 Comment(0)
P
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.

Palikar answered 14/6, 2019 at 18:58 Comment(0)
Q
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/

Quartzite answered 31/5, 2021 at 7:9 Comment(0)
C
0

change the git bash lnk's target , remove the --cd-to-home

then add the path into start in:

here is mine enter image description here

then open git bash to test

enter image description here

Casework answered 20/4 at 9:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.