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.

2
  • Even if this was possible it would make both "C:\D\" and "D:\" correspond to same /D/ Commented Sep 1, 2016 at 9: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. Commented Sep 1, 2016 at 10:18

8 Answers 8

14

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

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

Sign up to request clarification or add additional context in comments.

2 Comments

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.
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.
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/...

2 Comments

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.
Right, mounting to root does not work. But I did not propose it.
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

Comments

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

Comments

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.

Comments

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/

Comments

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

Comments

0

I fixed it by deleting --cd-to-home from the Target field, so I only kept the path to the .exe file in the "Target" field. After that, I set the required path in the 'Start in' field. I hope this helps someone.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.