Skip to content

Gitbash terminal not opening to workspace folder. #23382

Closed

Description

@dmurphyinsaas

Type: Bug

Behaviour

When I open a Gitbash terminal window, rather than the path being set to current workspace directory as before, it is being set to some
C:/Users/myuser/AppData/Local/Programs/Microsoft VS Code path and it appears some venv is active.

Steps to reproduce:

  1. Create new Folder and open this folder in VS code
  2. Open Gitbash terminal window (Opens to workspace folder as expected)
  3. Create venv python -m venv venv
  4. Create a python file touch main.py
  5. Open this file from VS Code file explorer.
  6. Terminal name turns yellow and on hover there is link to relaunch, click this relaunch terminal link.
  7. Terminal relaunches, this time some venv is activated and the path is set to C:/Users/myuser/AppData/Local/Programs/Microsoft VS Code

Diagnostic data

launch.json configuration

no launch.json

Output for Python in the Output panel (View→Output, change the drop-down the upper-right of the Output panel to Python)

2024-05-08 11:58:29.486 [info] Experiment 'pythonaacf' is active
2024-05-08 11:58:29.486 [info] Experiment 'pythonCreateEnvOnPipInstall' is active
2024-05-08 11:58:29.486 [info] Experiment 'pythonRecommendTensorboardExt' is active
2024-05-08 11:58:29.486 [info] Experiment 'pythonREPLSmartSend' is active
2024-05-08 11:58:29.486 [info] Experiment 'pythonTerminalEnvVarActivation' is active
2024-05-08 11:58:29.486 [info] Experiment 'pythonTestAdapter' is active
2024-05-08 11:58:29.486 [info] Default formatter is set to null for workspace c:\Temp\TestVS3
2024-05-08 11:58:29.486 [info] > hatch env show --json
2024-05-08 11:58:29.486 [info] cwd: .
2024-05-08 11:58:29.486 [info] Python interpreter path: ~\.pyenv\pyenv-win\versions\3.11.3\python.exe
2024-05-08 11:58:29.533 [info] > conda info --json
2024-05-08 11:58:29.567 [info] > ~\.pyenv\pyenv-win\versions\3.11.3\python.exe -I ~\.vscode\extensions\ms-python.python-2024.7.11291009\python_files\get_output_via_markers.py ~\.vscode\extensions\ms-python.python-2024.7.11291009\python_files\interpreterInfo.py
2024-05-08 11:58:29.601 [info] > .\venv\Scripts\python.exe -I ~\.vscode\extensions\ms-python.python-2024.7.11291009\python_files\get_output_via_markers.py ~\.vscode\extensions\ms-python.python-2024.7.11291009\python_files\interpreterInfo.py
2024-05-08 11:58:29.788 [info] > ~\.pyenv\pyenv-win\bin\pyenv which python
2024-05-08 11:58:29.788 [info] cwd: .
2024-05-08 11:58:30.316 [info] > . ./venv/Scripts/activate && echo 'e8b39361-0157-4923-80e1-22d70d46dee6' && python ~/.vscode/extensions/ms-python.python-2024.7.11291009/python_files/printEnvVariables.py
2024-05-08 11:58:30.316 [info] shell: bash
2024-05-08 11:58:30.498 [info] > ~\.pyenv\pyenv-win\versions\3.10.11\python.exe ~/.vscode/extensions/ms-python.python-2024.7.11291009/python_files/printEnvVariables.py
2024-05-08 11:58:30.498 [info] shell: bash
2024-05-08 11:58:30.591 [info] Setting environment variable MSYS in collection to disable_pcon disable_pcon {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-05-08 11:58:30.591 [info] Prepending environment variable PATH in collection with c:\Users\asus\.vscode\extensions\ms-python.python-2024.7.11291009\python_files\deactivate\bash;C;C:\Temp\TestVS3\venv\Scripts;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Users\asus\bin; {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-05-08 11:58:30.591 [info] Prepending environment variable PS1 in collection with (venv)  {"applyAtShellIntegration":true,"applyAtProcessCreation":false}
2024-05-08 11:58:30.591 [info] Setting environment variable PWD in collection to C:/Users/asus/AppData/Local/Programs/Microsoft VS Code {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-05-08 11:58:30.591 [info] Setting environment variable PYTHONIOENCODING in collection to utf-8 {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-05-08 11:58:30.591 [info] Setting environment variable PYTHONUNBUFFERED in collection to 1 {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-05-08 11:58:30.591 [info] Setting environment variable VIRTUAL_ENV in collection to C:\Temp\TestVS3\venv {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-05-08 11:58:30.591 [info] Setting environment variable VIRTUAL_ENV_PROMPT in collection to (venv)  {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-05-08 11:58:30.592 [info] Send text to terminal: C:/Users/asus/.pyenv/pyenv-win/versions/3.10.11/python.exe c:\Users\asus\.vscode\extensions\ms-python.python-2024.7.11291009\python_files\printEnvVariablesToFile.py c:\Users\asus\.vscode\extensions\ms-python.python-2024.7.11291009\python_files\deactivate\bash\envVars.txt
2024-05-08 11:58:31.789 [info] Starting Pylance language server.
2024-05-08 11:58:31.941 [info] Python interpreter path: c:\Temp\TestVS3\venv\Scripts\python.exe
2024-05-08 11:59:00.599 [error] Failed to initialize deactivate script C:\Program Files\Git\bin\bash.exe Error: "c:\Users\asus\.vscode\extensions\ms-python.python-2024.7.11291009\python_files\deactivate\bash\envVars.txt" file not created
    at Timeout.<anonymous> (c:\Users\asus\.vscode\extensions\ms-python.python-2024.7.11291009\out\client\extension.js:2:273765)
    at listOnTimeout (node:internal/timers:569:17)
    at processTimers (node:internal/timers:512:7)

Output for Python Debugger in the Output panel (View→Output, change the drop-down the upper-right of the Output panel to Python Debugger)

2024-05-08 11:58:29.522 [info] Name: Python Debugger
2024-05-08 11:58:29.523 [info] Module: debugpy

Extension version: 2024.7.11291009
VS Code version: Code 1.89.0 (b58957e67ee1e712cebf466b995adf4c5307b2bd, 2024-05-01T02:09:22.859Z)
OS version: Windows_NT x64 10.0.22631
Modes:

  • Python version (& distribution if applicable, e.g. Anaconda): 3.11.3
  • Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Venv
  • Value of the python.languageServer setting: Default
User Settings


languageServer: "Pylance"

Installed Extensions
Extension Name Extension Id Version
.NET Install Tool ms-dotnettools.vscode-dotnet-runtime 2.0.5
C# ms-dotnettools.csharp 2.28.11
ChatGPT - Genie AI genieai.chatgpt-vscode 0.0.10
Code Spell Checker streetsidesoftware.code-spell-checker 3.0.1
Dev Containers ms-vscode-remote.remote-containers 0.362.0
Docker ms-azuretools.vscode-docker 1.29.1
DotENV mikestead.dotenv 1.0.1
Draw.io Integration hediet.vscode-drawio 1.6.6
Git History donjayamanne.githistory 0.6.20
GitHub Actions github.vscode-github-actions 0.26.2
GitHub Copilot GitHub.copilot 1.187.0
GitHub Copilot Chat GitHub.copilot-chat 0.15.0
GitHub Pull Requests GitHub.vscode-pull-request-github 0.88.0
GitLens — Git supercharged eamodio.gitlens 14.9.1
IntelliCode VisualStudioExptTeam.vscodeintellicode 1.3.1
IntelliCode API Usage Examples VisualStudioExptTeam.intellicode-api-usage-examples 0.2.8
JavaScript Debugger ms-vscode.js-debug 1.89.0
JavaScript Debugger Companion Extension ms-vscode.js-debug-companion 1.1.2
Jupyter ms-toolsai.jupyter 2024.4.0
Jupyter Cell Tags ms-toolsai.vscode-jupyter-cell-tags 0.1.9
Jupyter Keymap ms-toolsai.jupyter-keymap 1.1.2
Jupyter Notebook Renderers ms-toolsai.jupyter-renderers 1.0.17
Jupyter Slide Show ms-toolsai.vscode-jupyter-slideshow 0.1.6
Mocha sidebar maty.vscode-mocha-sidebar 0.22.2
Pylance ms-python.vscode-pylance 2024.5.1
Python ms-python.python 2024.7.11291009
Python Debugger ms-python.debugpy 2024.6.0
Rainbow CSV mechatroner.rainbow-csv 3.11.0
Swagger Viewer Arjun.swagger-viewer 3.1.2
Table Visualizer for JavaScript Profiles ms-vscode.vscode-js-profile-table 1.0.9
Test Adapter Converter ms-vscode.test-adapter-converter 0.1.9
Test Explorer UI hbenl.vscode-test-explorer 2.21.1
vscode-pdf tomoki1207.pdf 1.2.2
WSL ms-vscode-remote.remote-wsl 0.88.2
YAML redhat.vscode-yaml 1.14.0
System Info
Item Value
CPUs AMD Ryzen 5 5500U with Radeon Graphics (12 x 2096)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
Load (avg) undefined
Memory (System) 15.38GB (3.25GB free)
Process Argv --folder-uri file:///c%3A/Users/asus/Documents/github/insaas/insaas-notebooks-experiments --crash-reporter-id a9eaff0c-8dbb-48f1-a524-0a5dc444f644
Screen Reader no
VM 0%
A/B Experiments
vsliv368:30146709
vspor879:30202332
vspor708:30202333
vspor363:30204092
vswsl492:30256859
vstes627:30244334
vscoreces:30445986
vscod805cf:30301675
binariesv615:30325510
vsaa593cf:30376535
py29gd2263:31024239
c4g48928:30535728
azure-dev_surveyone:30548225
962ge761:30959799
pythongtdpath:30769146
welcomedialog:30910333
pythonidxpt:30866567
pythonnoceb:30805159
asynctok:30898717
pythontestfixt:30902429
pythonregdiag2:30936856
pyreplss1:30897532
pythonmypyd1:30879173
pythoncet0:30885854
h48ei257:31000450
pythontbext0:30879054
accentitlementsc:30995553
dsvsc016:30899300
dsvsc017:30899301
dsvsc018:30899302
cppperfnew:31000557
dsvsc020:30976470
pythonait:31006305
chatpanelt:31018789
dsvsc021:30996838
01bff139:31013167
pythoncenvptcf:31039767
dwnewjupyter:31039675

Activity

  1. anthonykim1 commented on May 8, 2024

    @anthonykim1

    Hello Danny (@dmurphyinsaas) Thanks for filing the issue.
    Is gitbash set as your default terminal profile? If so, try switching the default to something else like pwsh,bash, etc
    Potentially related: #22910 #23008

  2. dmurphyinsaas commented on May 10, 2024

    @dmurphyinsaas
    Author

    Thank you for your response.
    Yes, I do have gitbash as my default terminal profile. When I change the default profile to pwsh, then I can open bash terminals and they are at the workspace folder path.
    This has only been an issue in the past week. Do you guys know the cause ? Is there likely to be a fix ? TIA

  3. hiderline commented on May 10, 2024

    @hiderline

    I faced the same problem 3 days ago, after upgrade ms-python from v2024.4.1 to 2024.6.0
    Rollback to previous version didn't help. I use git bash and venv as well.
    Next day after upgrade, after project opening, there shown some venv is activated and the path is set to

    (venv)
    user@DESKTOP-NAME MINGW64 C:/Users/userName/AppData/Local/Programs/Microsoft VS Code

    'which python' command said that global python is used
    print(sys.prefix) - said that project's (venv) is used/activated
    but 'pip list' command shows again on global environment
    if I run simple script - there shown, that python from (venv) was used.

    deactivate command gives following result:
    grep: /c/Users/{userName}/.vscode/extensions/ms-python.python-2024.6.0/python_files/deactivate/bash/envVars.txt: No such file or directory - shown triple times and strange (venv) is deactivated then and jumps directly to proper project directory:

    user@DESKTOP-NAME MINGW64 C:/Project/Folder
    Then after I can activate/deactivate project properly.

    By the way, if during terminal start-up or relaunch, when strange (venv) is active, I go 'cd c:/Project/Folder' and try to activate proper project's (venv), than I get 2 (venv) activated! As following:

    (venv) (venv)
    user@DESKTOP-NAME MINGW64 C:/Users/userName/AppData/Local/Programs/Microsoft VS Code

  4. oribay-iker commented on May 15, 2024

    @oribay-iker

    Same here, Git Bash with a venv that worked just fine until a couple of weeks ago. In my case I had manually set up a cd to specific folder in bash.bashrc located in "C:\Program Files\Git\etc".

    The cd works, if I run pwd I can see i'm in the correct location, but the command prompt of git bash says "C:\Program Files\Microsoft VS Code"

  5. Okhnovsky commented on May 20, 2024

    @Okhnovsky

    Hi everyone!
    I had the same problem. My git bash was opening to "C:/Users/userName/AppData/Local/Programs/Microsoft VS Code" with active venv.
    Its happened after update python extensions to 2024.6.0
    To solve this problem you should to do this in VS Code:

    • ctrl + shift + P
    • Terminal: Configure Terminal Settings

    • Scroll down until "Shell Integration"
      image
    • And remove tick

    Kill your terminal and launch a new one

  6. anthonykim1 commented on May 29, 2024

    @anthonykim1

    Hello everyone, thanks for looking into this issue. Please note that Gitbash is not currently officially supported by Python extension, so please consider switching your default terminal to other such as cmd, bash, zsh, etc Reference: #22908 We may support Gitbash once we have more time/bandwidth in doing so.

  7. griffinator76 commented on May 29, 2024

    @griffinator76

    Anthony Kim (@anthonykim1) Gitbash has been the standard terminal everywhere I have worked using VS Code so it's surprising to hear you don't support this.

  8. 23 remaining items

  9. RyzenFromFire commented on Jan 29, 2025

    @RyzenFromFire

    I seem to have a related issue. I have MSYS2 UCRT64 as my default terminal profile with the following options:

    "terminal.integrated.profiles.windows": {
    	"bash (UCRT64)": {
    		"path": "C:\\MSYS64\\msys2_shell.cmd",
    		"args": [
    			"-defterm",
    			"-here",
    			"-no-start",
    			"-use-full-path",
    			"-ucrt64"
    		]
    	}
    },
    

    The above may solve the original issue of Git Bash not opening to the correct path for the integrated terminal, if that was the issue (this wasn't clear to me) - since Git Bash is based on MSYS (specifically MINGW64).

    My issue is that if the Python extension is active, when opening a Jupyter notebook for the first time in a new session of VS Code (i.e., once per restart of VS Code or per load of a profile with the extension enabled), a plain MSYS terminal opens in a new window. Most likely this is caused by the terminal (msys2_shell.cmd) being invoked without the arguments shown above (as doing so will result in the behavior I am seeing). I have tried using python.terminal.launchArgs to no avail. Suggestions?


    Specifications/Information:

    Windows 11 23H2

    VS Code:
    Version: 1.88.1 (system setup)
    Commit: e170252f762678dec6ca2cc69aba1570769a5d39
    Date: 2024-04-10T17:41:02.734Z
    Electron: 28.2.8
    ElectronBuildId: 27744544
    Chromium: 120.0.6099.291
    Node.js: 18.18.2
    V8: 12.0.267.19-electron.0
    OS: Windows_NT x64 10.0.22631

    (I'll note that I didn't upgrade to 1.89.0 due to a workflow-breaking issue, I think it was related to profiles).

    Python version (& distribution if applicable, e.g. Anaconda): 3.9.21 (although it seems to occur with any)
    Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Conda (although it seems to occur regardless)
    Value of the python.languageServer setting: Default

  10. anthonykim1 commented on Jan 29, 2025

    @anthonykim1

    Hi folks, I think this is coming from part of the implicit activation that is done from Terminal Env Var experiment.
    Adding "python.experiments.optOutFrom": ["pythonTerminalEnvVarActivation"] to your settings.json would prevent this from happening.

    But please note that you will start seeing explicit activate command source ...activate in your terminal.
    Let me know how this goes, meanwhile I'm going to try to further narrow down where in the experiment is this problem coming from.

  11. RyzenFromFire commented on Jan 29, 2025

    @RyzenFromFire

    Hi folks, I think this is coming from part of the implicit activation that is done from Terminal Env Var experiment. Adding "python.experiments.optOutFrom": ["pythonTerminalEnvVarActivation"] to your settings.json would prevent this from happening.

    Just tried adding "python.experiments.optOutFrom": ["pythonTerminalEnvVarActivation"] to my settings.json, it didn't resolve my issue. I can't speak for the original one, although like I said, I suspect the cause is similar. I will also note that for me, a separate window opens only when the Python extension is enabled and opened to a Jupyter notebook or Python source file (as far as I can tell, only Python-related files cause it) for the first time in a session or on a profile switch. This doesn't happen if I use a different default terminal, but I don't consider that a solution.

    But please note that you will start seeing explicit activate command source ...activate in your terminal. Let me know how this goes, meanwhile I'm going to try to further narrow down where in the experiment is this problem coming from.

    I don't see any explicit command activation - I suspect this is because the extension is executing the command but not properly transferring the launch arguments provided by either the profile definition ("args" under the appropriate profile object in "terminal.integrated.profiles.windows") or from "python.terminal.launchArgs".

  12. anthonykim1 commented on Jan 29, 2025

    @anthonykim1

    I should also note, you should reload after adding "python.experiments.optOutFrom": ["pythonTerminalEnvVarActivation".
    Also highly recommend deleting and recreating environment via Python extension command here:

    Image

    You should be seeing activation command on your terminal if you are opted out of the experiment. Watch out for yellow warning sign in terminal after doing all this, you should create a new terminal.

  13. RyzenFromFire commented on Jan 29, 2025

    @RyzenFromFire

    I restarted after adding the setting. If by reload, you mean the action Python: Clear Cache and Reload Window, I just tried that and it changed nothing.

    I forgot that while troubleshooting, I set "python.terminal.activateEnvironment": false. Reverting that to true , I see the explicit activation (conda.bat activate, when using Command Prompt as terminal, or activate followed by conda activate ... when using MSYS2 UCRT64). I'll note that the latter doesn't work, I have to use source activate ..., but I think that's due to my configuration being borked and not the extension. In any case, my issue isn't resolved by this.

    I don't see any yellow warnings. I did exit the previous instance of the terminal and relaunch in between each test though.

  14. monk-time commented on Jan 29, 2025

    @monk-time

    Hi folks, I think this is coming from part of the implicit activation that is done from Terminal Env Var experiment.
    Adding "python.experiments.optOutFrom": ["pythonTerminalEnvVarActivation"] to your settings.json would prevent this from happening.

    Can confirm that the terminal launched in the proper dir after opting out from the experiment, also saw that source <...> line. Recreating the venv wasn't necessary for me.

    The annoying "Reactivating terminals..." message flashing in the status bar for ~30 sec after restarting VSCode also disappeared, I started seeing it after the directory issue started (so about half a year ago).

  15. anthonykim1 commented on Feb 22, 2025

    @anthonykim1

    Hi folks! I just merged in #24832 yesterday, which seem to resolve the issue.
    Can people try the latest pre-release of the Python extension on VS Code Insiders?
    Please make sure to Python Clear Cache and Reload and restart extensions after you update.

    Thanks!

  16. monk-time commented on Feb 23, 2025

    @monk-time

    Anthony Kim (@anthonykim1) I tried just switching to the pre-release extension on the current (non-Insider) VS Code version and can confirm that the cwd issue is finally gone!

  17. rachitp commented on Feb 28, 2025

    @rachitp

    The terminal launched in the proper directory, but the git status command failed. The environment variable HOME was set wrong which is probably the reason git command failed.
    $ git status
    fatal: unable to access 'C:\Users?achit/.config/git/config': Invalid argument
    $ echo $HOME
    achiters
    <--- wrong this is not home. seems something with forward and back slashes in the path fields didn't go well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-terminalbugIssue identified by VS Code Team member as probable bugneeds spikeLabel for issues that need investigation before they can be worked on.verification-neededVerification of issue is requestedverifiedVerification succeeded

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions