Buttle Butkus
Buttle Butkus

Reputation: 9466

Git Bash on windows is stuck in some kind of linux shell environment

Usually I start it up and I'm located in my windows user directory. I can see all my project folders with a quick ll. The last few times I've used it, though, I seem to be stuck in some pseudo linux environment. pwd says I'm at /. And if I cd .. I go nowhere.

And none of the folders look like I'm on windows. What is going on here?

Buttle@butkus MINGW64 /
$ ll
total 3412
drwxr-xr-x 1 Buttle 197609       0 Oct 29 14:13 bin/
drwxr-xr-x 1 Buttle 197609       0 Oct 29 14:13 cmd/
drwxr-xr-x 1 Buttle 197609       0 Oct 29 14:13 dev/
drwxr-xr-x 1 Buttle 197609       0 Oct 29 14:13 etc/
-rwxr-xr-x 1 Buttle 197609  140800 Oct 19 20:06 git-bash.exe*
-rwxr-xr-x 1 Buttle 197609  140288 Oct 19 20:06 git-cmd.exe*
drwxr-xr-x 1 Buttle 197609       0 Oct 29 14:13 mingw64/
dr-xr-xr-x 9 Buttle 197609       0 Feb  2 01:35 proc/
-rw-r--r-- 1 Buttle 197609   57831 Oct 19 20:17 ReleaseNotes.html
drwxr-xr-x 1 Buttle 197609       0 Feb  2 01:35 tmp/
-rw-r--r-- 1 Buttle 197609  968936 Oct 29 14:13 unins000.dat
-rwxr-xr-x 1 Buttle 197609 1300779 Oct 29 14:09 unins000.exe*
drwxr-xr-x 1 Buttle 197609       0 Oct 29 14:13 usr/

Buttle@butkus MINGW64 /
$

As stated above, I'm using Windows. But the reason I'm confused is that I used to start out inside my regular Windows filesystem's user directory, from which I could just cd into the project directory. Now I don't know where I am. pwd says I'm in the root directory but I cannot find any of my Windows filesystem or any of my git projects. Git UI for Windows (again, on Windows) is working fine but I prefer the command line.

Edit: Notes on solutions

Thanks to @Tim Biegeleisen for his answer. I also found this solution: https://stackoverflow.com/a/10652224/631764

I edited the original Git Bash shortcut in C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Git and removed --cd-to-home from the start up options. Then I changed the "Start in" section to go to my projects directory, so that it now looks like this: %HOMEDRIVE%%HOMEPATH%\Projects

I had to delete my Taskbar icon - it had somehow gotten disconnected from its roots - and then after pinning the Git Bash shortcut to my taskbar, everything worked as expected. If it becomes disconnected again, I will just delete and restore the Taskbar pin again.

Upvotes: 3

Views: 4230

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 521289

From what I can, this is normal behavior for the Git Bash tool. I was able to reproduce the Linux-esque directory listing obtained by typing ll. The reason pwd is returning / is because your bash is starting up in the root directory, which defaults to the location where Git was installed on your machine (C:\Program Files\Git on my computer). When you type cd .. you can't go anywhere, because you are already in the root position in the directory tree.

To change to your user directory you can try the following:

tbiegeleisen@niihau MINGW64 /
$ cd C:

tbiegeleisen@niihau MINGW64 /c
$ cd Users/tbiegeleisen/

I think the only difference in behavior you are seeing is that the Git bash may have someone "forgotten" in which directory it should start. If you use the two commands I gave above, you can easily navigate back to the directory containing your source code.

Upvotes: 6

Related Questions