1

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

  • 32- and 64-bit
  • Run as admin
  • sh.exe instead of git-bash.exe (and Run as admin)

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

Bob
  • 4,576
  • 7
  • 39
  • 107
  • 1
    If your git-bash builds the prompt in bash shell, double check if it's working fine. – Philippe Mar 04 '22 at 18:58
  • @Philippe I do not understand your comment. – Bob Mar 04 '22 at 20:14
  • 2
    git-bash tries to get current git branch and shows it on the prompt. Can you just do `PS1='$ '` to see if it improves ? – Philippe Mar 04 '22 at 20:28
  • @Philippe it improved a lot. `pwd` and other commands are now as fast as on `Cygwin`. – Bob Mar 04 '22 at 20:31
  • @Philippe the problem is not only in a Git directory. Ignoring your temporary fix, `pwd` was slow in any directory when I was in `Git-Bash` – Bob Mar 04 '22 at 20:33
  • 2
    I know. Git-Bash tries to detect if current directory is a git directory even though it's not. So now you need to troubleshoot why Git-Bash has difficulty to do that. – Philippe Mar 04 '22 at 20:38
  • @Philippe you'd think a bug this obvious would be fixed by now. – Bob Mar 04 '22 at 20:39
  • It may not be a bug, could be related to your environment, particularly your git settings. – Philippe Mar 04 '22 at 20:56
  • 1
    We can't see your original value of `PS1`. Quite obviously you have configured a prompt command which does something which takes time, but we can't help you further. – tripleee Mar 14 '22 at 19:38
  • 1
    https://github.com/git-for-windows/git/issues/2879 – LMC Mar 15 '22 at 00:11
  • Please open a new console, hit `declare -p PS1` and/or `echo ${PS1@A}`, then add the result to your question. – F. Hauri - Give Up GitHub Mar 15 '22 at 06:31
  • From your description, it looks that the fancy things you do inside your `PS1` take more time in git-bash than in Cygwin bash. Did you use the same `PS1` setting in Cygwin bash? If not, you are comparing apple and pears. – user1934428 Mar 15 '22 at 12:12
  • You are invoking `__git_ps1` from your PS1: Try to run the command manually in both environments. I suspect it takes much longer under Cygwin. – user1934428 Mar 17 '22 at 10:02
  • @user1934428 `__git_ps1` doesn't work in Cygwin – Bob Mar 17 '22 at 22:17
  • Why are you using it then? – user1934428 Mar 19 '22 at 09:49
  • @user1934428 I'm using Git-Bash out of the box. – Bob Mar 24 '22 at 15:49
  • Did you already trace the execution of this command, to see where it takes most time? – user1934428 Mar 25 '22 at 13:01
  • @user1934428 how do I trace the execution of `__git_ps1` in Windows? – Bob Mar 30 '22 at 19:58
  • The issue is `__git_ps1` and there's [an open issue](https://stackoverflow.com/questions/4192014/git-ps1-extremely-slow-in-kernel-tree) – Bob Mar 30 '22 at 20:06
  • 1
    You type on the command line `set -x; __git_ps1; set +x`. – user1934428 Mar 31 '22 at 06:42
  • @Bob: This assumes that __git_ps1 is a **function** (which I believe to be the case). I would check this before with `type __git_ps1`. If it is a shell script, you would use a different approach. – user1934428 Mar 31 '22 at 06:45

4 Answers4

1

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.

Philippe
  • 20,025
  • 2
  • 23
  • 32
0

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)

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

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.

0

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.

David
  • 1