4

I have read posts similar to this one; it seems my issue is different.

I suspect I'm having this issue due to my .bash_profile because when I delete it and open the terminal again it starts up quickly, and it says:

WARNING: Found ~/.bashrc but no ~/.bash_profile, ~/.bash_login or ~/.profile.

This looks like an incorrect setup.
A ~/.bash_profile that loads ~/.bashrc will be created for you.

.bash_profile generated

# generated by Git for Windows
test -f ~/.profile && . ~/.profile
test -f ~/.bashrc && . ~/.bashrc

.bashrc

if [ -t 1 ]; then
exec zsh
fi

I also have a HOME variable in my environment varaibles.

3
  • You are starting ZSH. Any particular reason for that?
    – Daniel B
    Jul 24, 2022 at 8:57
  • Yes, I use zsh? Jul 24, 2022 at 9:57
  • 1
    By deleting .bash_profile, you are no longer starting ZSH. I suggest you investigate ZSH startup performance.
    – Daniel B
    Jul 24, 2022 at 10:02

3 Answers 3

5

In my case I was using MING64 with Git bash for Windows. It took a solid 15 seconds to load every window. It turns out the .bashrc in %USERPROFILE% was the culprit.

I had NVM installed on my system and these lines caused every terminal window to load for a long time.

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm

I commented out the last line and now, bash only takes a second to load. I rarely use NVM so there is no need to load it on every startup.

2
  • for me it was source <(ng completion script) Jan 12 at 16:21
  • This is great, but unfortunately this prevents nvm from working. To overcome this, I have added the nvm init scripts into a bashrc declared function: function nvm_init() { [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion}
    – ktsangop
    Feb 23 at 7:42
1

I had the same issue. nothing helped. Git bash was insanely slow doing ANYTHING, just hitting enter took 20 seconds to get a new prompt.

My issue ended up being page file settings. I have 64GB ram and all M.2 SSDs, so I didn't think I needed so much page file.. I had reduced it to 256-2048M range manually set.. After changing it back to system managed, git bash is back to fast.. but also got corrupted again and eventually it happened several more times.

Now I have page file off completely and git bash is screaming fast.

1
  • 1
    An added benefit. If there is a BSOD and it dumps memory. The pagefile needs to be about 1.5 times the memory size. Otherwise your error gets an ertor. Jan 28, 2023 at 20:32
0

I've tested the same scenario on brand new git instalaltion on Windows 10 and got the same behavoir. Indeed, renaming or removing .bash_profile in C:\Users\<username> folder removes bash startup delays. But for some time. Of course, I had HOME env var set. After restating Terminal and cmd (I tested form both) usually the first run of bash in shell is still slow but starts quicker after some exit/start cycles.

Then I suspected the .bashrc file which is located in the ~/ directory (/home/<username>) of the linux distribution because by default it is 3.7K and may cause some slowness. Renaming it I've got the same behavior: if I run bash multiple times in the same cmd/terminal (which uses WSL under the hood) then consequent run become very fast exept the first one.

I've also tested running bash without profile which was slwo the same way:

 Measure-Command { wsl -e bash -noprofile -norc -c "echo Hello" }

TotalSeconds      : 29,3953657

The consequent run in the same window was quick:

Measure-Command { wsl -e bash -noprofile -norc -c "echo Hello" }

TotalSeconds      : 0,2136513

So, I believe the real issue is how wsl works with memory in W10 and the page file, and/or caches data for emulation.

Also you should notice that running bash command you actually call wsl, not the git bash:

C:\Users\user>where bash
C:\Windows\System32\bash.exe
C:\Users\user\AppData\Local\Microsoft\WindowsApps\bash.exe

But the git bash is actually called from here:

"C:\Program Files\Git\git-bash.exe" --cd-to-home

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .