Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> 關於 Linux

Git 在 Windows 上報錯「exit code 128/1」:TortoiseGit SSH Client 設定修正指南

編輯:關於 Linux

Windows 上使用 TortoiseGit 執行 git pull/push 時彈出 Git did not exit cleanly (exit code 128) 或 exit code 1,根因是 TortoiseGit 預設使用自帶的 TortoisePlink.exe 作為 SSH Client,與系統安裝的 Git for Windows ssh.exe 金鑰格式、Agent 整合不相容。修改 SSH Client 路徑即可解決。

TortoiseGit exit code 128 錯誤視窗

錯誤現象

git.exe pull --progress -v origin master
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Git did not exit cleanly (exit code 128)

根因分析

  • TortoiseGit → Settings → Network → SSH Client 預設:C:\Program Files\TortoiseGit\bin\TortoisePlink.exe
  • TortoisePlink 基於 PuTTY 格式金鑰 (.ppk),而 Git for Windows / OpenSSH 使用 OpenSSH 格式 (id_rsa, id_ed25519)。
  • 雙方金鑰格式、SSH Agent (Pageant vs ssh-agent)、known_hosts 格式均不互通,導致連線失敗。

修正步驟

  1. 開啟 TortoiseGit 設定:
    右鍵專案資料夾 → TortoiseGit → Settings
  2. 左側選單 Network
  3. SSH Client 路徑修改為 Git for Windows 內建 ssh.exe:
    C:\Program Files\Git\bin\ssh.exe
    (若為 32 位 Git 安裝在 64 位系統:C:\Program Files (x86)\Git\bin\ssh.exe)
  4. 點擊 OK 套用。

驗證

# 再次嘗試 pull
git pull origin master
# 應正常提示輸入 passphrase 或自動透過 ssh-agent 驗證

進階:配合 SSH Agent 免輸入密碼

# PowerShell (管理員)
Start-Service ssh-agent
Set-Service ssh-agent -StartupType Automatic

# 加入金鑰
ssh-add ~/.ssh/id_ed25519
# 輸入 passphrase 一次,後續 TortoiseGit 操作自動使用 Agent

常見誤區

誤區正確認知
以為是 Git 版本問題實為 SSH Client 選擇問題,升級 Git 無效
繼續用 TortoisePlink 並轉換金鑰可行但維護成本高,不如直接改用 ssh.exe
修改後仍報錯檢查 C:\Program Files\Git\bin\ssh.exe 是否存在、%PATH% 是否含 Git bin 目錄

將 TortoiseGit SSH Client 指向 Git\bin\ssh.exe,即可讓 Windows 上的 Git 圖形操作與命令列共用同一套 OpenSSH 金鑰體系,徹底消除 exit code 128/1 困擾。

Copyright © Windows教程網 All Rights Reserved