简体   繁体   中英

"git branch" command is slow from Git Bash on Windows

I only have one branch main but when I execute the git branch command, it took about 30 seconds to complete. Other commands like git status does not have this performance issue. What are some of the things that I can check here?

Git version is 2.36.0 running on Windows 10.

UPDATE:

  • Also opening up Git Bash is slow (around 20 seconds). I tried the solution https://stackoverflow.com/a/47542488/1160753 . Git Bash opened up quickly after that change but the subsequent action of opening up the Git Bash is back to take approximately 20 seconds.
  • When Git Bash is executed under "Run As Administrator", git branch completed quickly. BUT that is not every single time. There are times that the same command takes 30 seconds to complete (this is without any additional branch)

Tl;dr

On Windows, when the PC is in a domain, make sure that the domain controller is reachable.

Details

The shell and command line tools that are distributed with Git for Windows are derived from the MSYS2 project , which is based on a variant of the Cygwin library. As part of the program startup routine, the library does several name lookups. When the system is registered in a domain, this lookup goes to the domain controller. In the case when the domain controller is not reachable, the lookup waits for time-outs. This causes the delays.

The results of the lookup is cached by Windows. Therefore for a short time, subsequent startups do not have to wait for the time-outs. But ultimately the cache expires and the next program invocation has to wait again.

The Git program, git.exe , is not based on the Cygwin library and does not need the name lookup. It can run without delay. However, many Git commands spawn a pager, typically less , which does suffer from the delay; therefore, it appears as if Git itself would be delayed. (Not that it matters; the user experience is bad either way.)

On top of that there are many other cases where Git runs a command line tool: hooks, textconv filters, ssh, etc. All of them can suffer from the delay.

EDIT: I am currently testing the following change. Do NOT make this change to your system unless you know exactly what the security implications are.

I used mkpasswd and mkgroup to cache the current domain information locally:

mkpasswd >> /etc/passwd
mkgroup >> /etc/group

Then I removed duplicates from the files. (But /etc/group did not exist before these commands.)

This idea was taken from the Cygwin FAQ .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM