6

I was able to integrate git-bash in the (new) Windows10 Terminal. (This app from Microsoft's AppStore is able to host more than one console-app in one single window, organized in tabs.)

But whenever I open a new tab for git-bash, it sets the working directory to /c/WINDOWS/system32.

I would prefer to have the same working directory as in the tab from where I opened the new tab.
Is there a possibility for that?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
frochi42
  • 71
  • 1
  • 3

3 Answers3

6

In Windows Terminal click on the arraw down button and click Settings (alternatively, press Ctrl+Shift+,). This will open the settings.json file. Then add "startingDirectory": "" to the GitBash profile. This should change the default directory to where you opened the terminal.

It should be like this:

{
    "guid": "{e9961a24-1111-2222-3333-835a2d22397d}",
    "hidden": false,
    "name": "Git Bash",
    "icon" : "%PROGRAMFILES%\\git\\mingw64\\share\\git\\git-for-windows.ico",
    "commandline": "%PROGRAMFILES%\\Git\\bin\\bash.exe -l -i",
    "historySize" : 9001,
    "padding" : "0, 0, 0, 0",
    "snapOnInput" : true,
    "useAcrylic" : true,
    "startingDirectory": "~",
    "acrylicOpacity": 0.9          
}

Notes:

  • "startingDirectory": "~" in this config makes Git Bash start in the user profile directory.
  • You can replace e9961a24-1111-2222-3333-835a2d22397d with any other unique UUID.
izogfif
  • 6,000
  • 2
  • 35
  • 25
Jalal
  • 6,594
  • 9
  • 63
  • 100
  • 1
    Funny thing that it (~ sign) was working for me for a long time, and recently I started seeing: [error 0x8007010b when launching `%PROGRAMFILES%/Git/bin/bash.exe --login -i -l'] Could not access starting directory "C:\WINDOWS\system32\~" Once changed to empty is working fine, but does not open user profile directory. – Nyuno May 27 '21 at 13:24
1

Using the "startingDirectory": "%HOMEDRIVE%%HOMEPATH%" setting works for me.

0

As noted here, check if your .bashrc has any cd directive.
And check first if said .bashrc is called at all when opening a new git bash tab in Windows Terminal: add an echo in said %USERPROFILE%\.bashrc.

But this issue might not be limited to git bash.
See if microsoft/terminal issue 3158 applies:

I've come with a workaround: change the starting directory.

Put this function into $PROFILE (make sure to adjust $path)

function sd {
   $path = >'C:\Users\Admin\AppData\Local\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json'
    ((Get-Content -path $path) -replace '"startingDirectory":.*', ("`"startingDirectory`": `"$pwd`"") -replace "\\", "\\") | Set-Content -Path $path
}

.. and you'll be able to a open new tab in the same directory almost with no hassle, just make sure to type sd before opening a new tab.

Of course, the drawback is that startingDirectory is changed every time the function is called.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250