Bob
Bob

Reputation: 4980

basic shell commands extremely slow on Git-Bash, sh.exe but fine on Cygwin

When I run basic commands like pwd and cd the command itself executes fast but the console hangs for 1 second before allowing me to execute another command.

I got the latest Git Bash portable and tried

But Cygwin does not have this problem.
In Cygwin, running pwd from the same directory as any Git Bash variant results in equally fast command completion but also there is no console hanging.

My Windows is: Version 10.0.19044 Build 19044

I have nVidia Quadro P3000

UPDATE from comments below:
It appears to be an issue with my Git installation but I chose the defaults so I don't know what it could be. When I execute PS1='$ ' in Git-Bash, I do not have the the 1-second pause after each command is executed.

UPDATE from comments below

$ echo ${PS1@A}
declare -x PS1='\[\033]0;$TITLEPREFIX:$PWD\007\]\n\[\033[32m\]\u@\h \[\033[35m\]$MSYSTEM \[\033[33m\]\w\[\033[36m\]`__git_ps1`\[\033[0m\]\n$ '

I did not change anything.
I download a version of portable Git For Windows, launch as admin and type ls, pwd, etc.

I went back to 2.24 but same behavior.

I'm also going to try it on my personal PC since it could be my corporate antivirus that's causing this.

UPDATE

The issue is __git_ps1 and there's an open issue

Upvotes: 1

Views: 4120

Answers (4)

David
David

Reputation: 1

For me it was corrupt page file. Try clearing Windows page file and rebooting. Page file was constantly causing my git bash to hang for 20 seconds with just carriage returns. I've re-enabled page file several times and eventually it happens again. Clearing page file fixed it every time. I turn page file completely off now and git bash is screaming fast.

Upvotes: 0

Philippe
Philippe

Reputation: 26727

I think that __git_ps1 is the culprit.

As a test, put following code in /tmp/experiment.sh

if  [[ "$(type -t __git_ps1)" == 'function' ]]; then
  cd(){
    builtin cd "$@"
    __GIT_PS1=$('__git_ps1') # Calling original __git_ps1, only when changing directory.
  }
  __git_ps1_stub(){
    echo "$__GIT_PS1" # Now $PS1 will do this echo, instead of calling __git_ps1
  }
  alias __git_ps1=__git_ps1_stub # __git_ps1_stub will be called in $PS1
  cd . # Initialize $__GIT_PS1 for the first time.
fi

Then start a git-bash terminal, and run source /tmp/experiment.sh

If situation improves, you can put the code in ~/.bashrc

You'll need to change other commands (like pushd, popd, etc) if you use them to change directory.

Upvotes: 1

Pavel Samsonov
Pavel Samsonov

Reputation: 103

The problem may be related to slow resolution of computer network names. Since the computer name is involved in the command line. I advise you to add yourhostname and localhost to etc/hostname.

Upvotes: 0

VonC
VonC

Reputation: 1328522

Try first to simplify your PATH when testing your Git bash.
In a CMD, type

set "GH=C:\Program Files\Git"
set "PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0"
set "PATH=%GH%\bin;%GH%\cmd;%GH%\usr\bin;%GH%\mingw64\bin;%GH%\mingw64\libexec\git-core;%PATH%"

Then try again and type bash to enter a shell session.

By default, I get:

$ echo $PS1
\[\033]0;$TITLEPREFIX:$PWD\007\]\n\[\033[32m\]\u@\h \[\033[35m\]$MSYSTEM \[\033[33m\]\w\[\033[36m\]`__git_ps1`\[\033[0m\]\n$

And it is quite fast.
(Microsoft Windows 10.0.19044.1586, git version 2.35.1.windows.2)

Upvotes: 0

Related Questions