Git命令行执行速度过慢求助(附git pull追踪日志)
Git命令执行极慢问题排查与解决
问题概述
Git命令(如git pull)连接GitHub Enterprise时耗时超30秒,所有仓库均受影响,执行git gc无效,Git版本为2.44.0.windows.1。从追踪日志看,凭证管理器(credential helper)环节存在严重延迟,例如git credential-wincred store操作耗时近4秒,整个凭证处理流程占用了大部分时间。
追踪日志详情
06:59:13.583072 exec-cmd.c:243 trace: resolved executable dir: C:/Program Files/Git/mingw64/bin 06:59:13.594065 git.c:463 trace: built-in: git pull 06:59:13.614063 run-command.c:657 trace: run_command: git fetch --update-head-ok 06:59:14.009064 exec-cmd.c:243 trace: resolved executable dir: C:/Program Files/Git/mingw64/libexec/git-core 06:59:14.022066 git.c:463 trace: built-in: git fetch --update-head-ok 06:59:14.051063 run-command.c:657 trace: run_command: GIT_DIR=.git git remote-https origin https://some.github.enterprise/some-repo.git 06:59:14.439062 exec-cmd.c:243 trace: resolved executable dir: C:/Program Files/Git/mingw64/libexec/git-core 06:59:14.444062 git.c:750 trace: exec: git-remote-https origin https://some.github.enterprise/some-repo.git 06:59:14.447067 run-command.c:657 trace: run_command: git-remote-https origin https://some.github.enterprise/some-repo.git 06:59:14.846061 exec-cmd.c:243 trace: resolved executable dir: C:/Program Files/Git/mingw64/libexec/git-core 06:59:15.196064 run-command.c:657 trace: run_command: 'git credential-manager get' 06:59:15.707068 exec-cmd.c:243 trace: resolved executable dir: C:/Program Files/Git/mingw64/libexec/git-core 06:59:15.711066 git.c:750 trace: exec: git-credential-manager get 06:59:15.711066 run-command.c:657 trace: run_command: git-credential-manager get 06:59:16.651067 exec-cmd.c:243 trace: resolved executable dir: C:/Program Files/Git/mingw64/libexec/git-core 06:59:16.655064 git.c:463 trace: built-in: git config --null --list 06:59:22.612580 run-command.c:657 trace: run_command: 'git credential-manager store' 06:59:23.344581 exec-cmd.c:243 trace: resolved executable dir: C:/Program Files/Git/mingw64/libexec/git-core 06:59:23.347581 git.c:750 trace: exec: git-credential-manager store 06:59:23.347581 run-command.c:657 trace: run_command: git-credential-manager store 06:59:24.411583 exec-cmd.c:243 trace: resolved executable dir: C:/Program Files/Git/mingw64/libexec/git-core 06:59:24.417579 git.c:463 trace: built-in: git config --null --list 06:59:35.279580 run-command.c:657 trace: run_command: 'git credential-wincred store' 06:59:35.688606 exec-cmd.c:243 trace: resolved executable dir: C:/Program Files/Git/mingw64/libexec/git-core 06:59:35.692586 git.c:750 trace: exec: git-credential-wincred store 06:59:35.692586 run-command.c:657 trace: run_command: git-credential-wincred store 06:59:39.515582 run-command.c:657 trace: run_command: git rev-list --objects --stdin --not --exclude-hidden=fetch --all --quiet --alternate-refs 06:59:45.133144 run-command.c:1521 run_processes_parallel: preparing to run up to 1 tasks 06:59:45.133144 run-command.c:1549 run_processes_parallel: done 06:59:45.133144 run-command.c:657 trace: run_command: git maintenance run --auto --no-quiet 06:59:45.396143 exec-cmd.c:243 trace: resolved executable dir: C:/Program Files/Git/mingw64/libexec/git-core 06:59:45.402143 git.c:463 trace: built-in: git maintenance run --auto --no-quiet 06:59:49.491234 run-command.c:657 trace: run_command: git merge FETCH_HEAD 06:59:49.751234 exec-cmd.c:243 trace: resolved executable dir: C:/Program Files/Git/mingw64/libexec/git-core 06:59:49.755235 git.c:463 trace: built-in: git merge FETCH_HEAD Already up to date.
> git version git version 2.44.0.windows.1 > git pull
解决方案
1. 替换旧版凭证助手为GCM Core
旧的wincred凭证助手在Windows上容易出现性能问题,切换到官方推荐的Git Credential Manager Core:
- 移除旧的凭证配置:
git config --global --unset credential.helper - 设置使用GCM Core:
git config --global credential.helper manager-core
2. 禁用或调整凭证缓存
如果不需要凭证缓存,直接关闭以减少交互延迟:
git config --global credential.cache false
或者设置较短的缓存时长(例如1小时):
git config --global credential.helper 'cache --timeout=3600'
3. 检查并清理HTTPS代理设置
异常代理会导致连接延迟,查看当前代理配置:
git config --global --get https.proxy
如果存在无效代理,执行移除:
git config --global --unset https.proxy
4. 禁用自动维护功能
日志中显示自动维护git maintenance run占用时间,可关闭自动维护:
git config --global maintenance.auto false
内容的提问来源于stack exchange,提问作者Vincent Han
相关产品推荐
相关产品推荐

