12

My Git Bash terminal in VS Code started acting strange on Windows and I'm not sure what I did for it to be acting this way. It used to start in the workspace folder C:\Users\[User]\[path]\[to]\[Repo_folder] but now when I launch it, it starts in C:/Users/[User]/AppData/Local/Programs/Microsoft VS Code. I don't have the issue with the other terminal like Powershell or cmd. I've also noticed the HOME variable is not set properly. It should be C:\Users\EliotGodard but is set to C:\UsersiotGodard. I'm not sure if it's related or not. If I don't reset the HOME var to the correct value, I can't use the git command fatal: unable to access 'C:\Users?liotGodard/.config/git/config': Invalid argument. The HOME var is set properly when using the Git Bash UI though /c/Users/EliotGodard. It seems like it could be related to the way Windows concatenates the path?

I've searched a long time for similar issues but I'm not sure how to describe it when doing my research. Thank you for the any help you can provide.

I've tried uninstalling and reinstalling both Git Bash and VS Code with no luck. I've also tried to set the workspace setting "terminal.integrated.cwd": "${workspaceFolder}" and it does work for Powershell and cmd but not for Git Bash.

2
  • Deleting the VS CODE settings helped me solve this problem. Commented May 5, 2024 at 17:02
  • Please copy and paste the output of the Help: About command (run in the command palette) into your question post. Does this happen when you reload VS Code with extensions disabled (use the Developer: Reload With Extensions Disabled command in the command palette)? If not, then do an extension bisect to figure out what extension is causing it. Commented May 6, 2024 at 7:52

4 Answers 4

16

Alright for anyone interested I managed to find a fix. Not sure why it works the way it does but it will do for now. The culprit was this line:

"terminal.integrated.defaultProfile.windows": "Git Bash"` 

Removing it would put back the default terminal to Powershell but at least when launching Bash from the dropdown next to the + button it would start Bash in the right folder with the HOME var set properly. The workaround was to set this in the settings.json

 "terminal.integrated.profiles.windows": { "custom-bash": { "path": "C:\\PROGRA~1\\Git\\bin\\bash.exe", "args": [ "--cd=${workspaceFolder}" ] } }, "terminal.integrated.defaultProfile.windows": "custom-bash", 

If anyone can explain that I'd be interested to know. Cheers

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

2 Comments

If you are in a workspace with many projects is better to set in args "--cd=."
Thanks for this. I did not create a "custom-bash" but added "args": ["--cd=."], under "terminal.integrated.profiles.windows" > "Git Bash" in settings,json
14

In settings.json, section "terminal.integrated.profiles.windows", add "args": ["--cd=."] in "Git Bash" entry like that:

 "Git Bash": { "source": "Git Bash", "args": ["--cd=."] }, 

2 Comments

This worked for me (and anything else did before)
This worked, thank you!
2

I had the same issue. For me worked the following:

  1. Open settings (Features -> Terminal -> Default Profile Windows) and turn it to "null" for both User and Workspace.
  2. Then switch (Features -> Terminal -> Integrated Cwd) to "${workspaceFolder}"
  3. Then turn (Features -> Terminal -> Default Profile Windows) back to "Git Bash" for both User and Workspace.
  4. Reload all terminals.

After these steps my bash terminal began to start up in project root dir instead of AppData\Local\Programs\Microsoft VS Code.

1 Comment

some things still cant be solved by chatgpt :)
0

My bash.exe does not have a --cd argument.

Using this instead worked for me:

"terminal.integrated.profiles.windows": { "Git Bash": { "path": "C:\\Program Files\\Git\\bin\\bash.exe", "args": ["--login", "-c", "cd \"${workspaceFolder}\" && bash"], "icon": "terminal-bash" } } 

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.