16

When using git on windows normally (such as git push and git pull), it will sometimes be very slow. Running git pull over and over again returns within two seconds most of the time, but about 1/6 of attempts take about a minute.

I have set git config --global core.preloadindex and git config --global core.fscache to true.

Examples after running set GIT_TRACE=1

Slow:

$ git pull
14:11:03.166594 git.c:371               trace: built-in: git 'pull'
14:11:03.168594 run-command.c:350       trace: run_command: 'fetch' '--update-head-ok'
14:11:03.186596 git.c:371               trace: built-in: git 'fetch' '--update-head-ok'
14:11:03.189596 run-command.c:350       trace: run_command: 'git-remote-https' 'origin' 'https://[...].git'
14:11:03.204598 run-command.c:350       trace: run_command: 'git credential-manager get'
14:11:46.400917 git.c:607               trace: exec: 'git-credential-manager' 'get'
14:11:46.400917 run-command.c:350       trace: run_command: 'git-credential-manager' 'get'
14:11:47.828059 run-command.c:350       trace: run_command: 'git credential-manager store'
14:11:47.869064 git.c:607               trace: exec: 'git-credential-manager' 'store'
14:11:47.869064 run-command.c:350       trace: run_command: 'git-credential-manager' 'store'
14:11:47.980075 run-command.c:350       trace: run_command: 'rev-list' '--objects' '--stdin' '--not' '--all' '--quiet'
14:11:47.991076 run-command.c:350       trace: run_command: 'rev-list' '--objects' '--stdin' '--not' '--all' '--quiet'
14:11:47.999077 git.c:371               trace: built-in: git 'rev-list' '--objects' '--stdin' '--not' '--all' '--quiet'
14:11:48.005077 run-command.c:1130      run_processes_parallel: preparing to run up to 1 tasks
14:11:48.005077 run-command.c:1162      run_processes_parallel: done
14:11:48.005077 run-command.c:350       trace: run_command: 'gc' '--auto'
14:11:48.014078 git.c:371               trace: built-in: git 'gc' '--auto'
14:11:48.017078 run-command.c:350       trace: run_command: 'merge' 'FETCH_HEAD'
14:11:48.025079 git.c:371               trace: built-in: git 'merge' 'FETCH_HEAD'
Already up-to-date.

Fast:

$ git pull
14:12:25.432820 git.c:371               trace: built-in: git 'pull'
14:12:25.434820 run-command.c:350       trace: run_command: 'fetch' '--update-head-ok'
14:12:25.451821 git.c:371               trace: built-in: git 'fetch' '--update-head-ok'
14:12:25.454822 run-command.c:350       trace: run_command: 'git-remote-https' 'origin' 'https://[...].git'
14:12:25.472824 run-command.c:350       trace: run_command: 'git credential-manager get'
14:12:25.497826 git.c:607               trace: exec: 'git-credential-manager' 'get'
14:12:25.497826 run-command.c:350       trace: run_command: 'git-credential-manager' 'get'
14:12:26.904967 run-command.c:350       trace: run_command: 'git credential-manager store'
14:12:26.941970 git.c:607               trace: exec: 'git-credential-manager' 'store'
14:12:26.941970 run-command.c:350       trace: run_command: 'git-credential-manager' 'store'
14:12:27.050981 run-command.c:350       trace: run_command: 'rev-list' '--objects' '--stdin' '--not' '--all' '--quiet'
14:12:27.060982 run-command.c:350       trace: run_command: 'rev-list' '--objects' '--stdin' '--not' '--all' '--quiet'
14:12:27.068983 git.c:371               trace: built-in: git 'rev-list' '--objects' '--stdin' '--not' '--all' '--quiet'
14:12:27.074984 run-command.c:1130      run_processes_parallel: preparing to run up to 1 tasks
14:12:27.074984 run-command.c:1162      run_processes_parallel: done
14:12:27.074984 run-command.c:350       trace: run_command: 'gc' '--auto'
14:12:27.082985 git.c:371               trace: built-in: git 'gc' '--auto'
14:12:27.085985 run-command.c:350       trace: run_command: 'merge' 'FETCH_HEAD'
14:12:27.092986 git.c:371               trace: built-in: git 'merge' 'FETCH_HEAD'
Already up-to-date.

Edit:

After running git config --global credential.helper "" the lines in output containing credential-manager are replaced by:

17:18:44.139589 run-command.c:350       trace: run_command: 'bash' '-c' 'cat >/dev/tty && read -r -s line </dev/tty && echo "$line" && echo >/dev/tty'
Password for 'https://[...]':

A delay occurs sometimes right before the Password line is displayed, with the same duration and frequency (as far as I can tell, from about 20 tests) as before.

hurturk
  • 5,214
  • 24
  • 41
usernumber
  • 541
  • 5
  • 15
  • Did you try and deactivate the real-time analysis of your anti-virus? – VonC Mar 14 '17 at 14:21
  • @VonC: I'm experiencing same problem as OP, I got ESET. When anti-virus is disabled, the issue still occurs. – Tatranskymedved Mar 14 '17 at 14:27
  • @Tatranskymedved Is is Windows 10, 7? Git 2.12? – VonC Mar 14 '17 at 14:29
  • Win10 x64 Pro, git version 2.10.2.windows.1 – Tatranskymedved Mar 14 '17 at 14:29
  • @VonC: I've just update to `git version 2.12.0.windows.1`, issue is still there – Tatranskymedved Mar 14 '17 at 14:44
  • @Tatranskymedved For testing, can you simplify your path with `set PATH=\bin;\usr\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0` (replace `` by your Git 2.12 installation path). And then test Git again in your CDM session with that simplified PATH? – VonC Mar 14 '17 at 14:50
  • @Tatranskymedved Sorry, I can't from work, I will follow up in a few hours – VonC Mar 14 '17 at 14:59
  • @VonC ok, no prob, I changed the `PATH` to simplified version, output is still the same – Tatranskymedved Mar 14 '17 at 15:00
  • 1
    My team and I used to have the same issue on a corporate server. When the repo was compressed (probably `git gc` or similar) or reorganised due to migrattion from one server to another, suddenly pushes were quick again. So maybe it helps to gc the upstream repo. – kriegaex Mar 14 '17 at 17:19
  • @kriegaex It is great suggestion, however it seems not be the case as the issue occurs during authentication (on `git credential-manager get` command) – Tatranskymedved Mar 15 '17 at 08:49
  • If you are right that it is about authentication, then probably it does not help. But can it hurt? You can still give it a try, maybe with a copy of the repo if it is not too big. Good luck to you on the authentication part. – kriegaex Mar 15 '17 at 10:28
  • Could you try and remove any credential manager to see if (afte rmanual authentication) the push is fast? – VonC Mar 15 '17 at 20:15
  • @VonC Yes, manual authentication is fast. As visible from above the problem seems to be directly with authentication. I'm not really "smart" from the authentication flow - it is not described much on git-svn web. Re-entering link to chat: http://chat.stackoverflow.com/rooms/138027/discussion-between-tatranskymedved-and-vonc – Tatranskymedved Mar 16 '17 at 09:49
  • @Tatranskymedved sorry, still at work ;) did you see in `git config -l` if you see any `credential.helper` line? – VonC Mar 16 '17 at 09:57
  • @VonC `credential.helper=manager` . FYI: I tried to reinstall GIT-SVN without the creds. manager & it worked fast (but I had to enter my credentials each time). Once working with manager, it is slow, but after approx. 30 secs it authenticate me and it works. – Tatranskymedved Mar 16 '17 at 10:02
  • Such very long delays only ever have two explanations. ESET is troublesome on a programmers' machine. But it is pretty close to a TCP connection timeout, 42 and 45 seconds are magic values. So probably that, use SysInternals' TcpView to see what it is trying to connect to. – Hans Passant Mar 17 '17 at 17:37

3 Answers3

6

Based on your trace, it seems that the authentication step is slow. I can see two main reason to this:

  • The server sometimes responds slowly. You won't be able to do anything on the client side.
  • Something is wrong with authentication on your side. The most probable cause I think, is that you may use a credential manager which cause the slowness. Try to disable it.
Guillaume Pascal
  • 845
  • 1
  • 9
  • 19
  • Well, disabling cred. manager will cause that I'm forced to enter password everytime. If there is any workaround or explanation why it is happening, it would be really appreacited. – Tatranskymedved Mar 17 '17 at 06:53
  • 1
    It is difficult to say why your cred. manager is slow without investigating. Check if there is any update for it. With a bit of luck there will be one and it will solve your issue. Otherwise, I am afraid that the best alternative I can suggest you is to try using ssh urls instead of https urls for your git repo. The auth will be done with a ssh key and the key password will be prompted only once per computer start. It may be better than nothing even if it is not as good as a cred. manager :-/ – Guillaume Pascal Mar 17 '17 at 19:34
  • try ssh as auth will happen with key-pair and will be valid per session. Also try to verify if there is any network delay / packet loss. – iSensical Mar 20 '17 at 16:37
4

Please prefer ssh over https. I assume you already have GitBash so you can follow this tutorial. Make sure you clone the repo into a new directory so you don't lose your current https setup and any local changes.

If problem persists, though it would be very likely to be network issue, you can consider ssh debugging shown in this answer.

hurturk
  • 5,214
  • 24
  • 41
4

TL;DR - My slow git (GCM) was fixed by disabling .net assembly binding on my machine (via fuslogvw).

I discovered it was due to a slow git credentials manager (GCM) by running git and the GCM in trace mode:

$ SET GIT_TRACE=1 
$ SET GCM_TRACE=1
$ git fetch

The logs showed the GCM was slow. When looking at the GCM with sysinternals' process monitor to figure out what was happening, I saw it was writing heavily to disk.

Now, it turned out the GCM is a .net process, and I had configured .net to log all assembly binds to disk for debugging some process a couple of days ago (via fuslogvw - fusion log viewer).

Disabling the binding logging fixed my problem and speed returned to normal.

Martijn Evens
  • 266
  • 3
  • 5
  • I didn't know about `GCM_TRACE`! +1. It is not mentioned in https://git-scm.com/book/gr/v2/Git-Internals-Environment-Variables, or in the Git repo itself: https://github.com/git/git/search?utf8=%E2%9C%93&q=GCM_TRACE&type=. It is in https://github.com/Microsoft/Git-Credential-Manager-for-Windows/search?utf8=%E2%9C%93&q=GCM_TRACE&type= – VonC Sep 13 '17 at 04:39