How to resolve git did not exit cleanly exit code 128 error on TortoiseGit?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
The TortoiseGit error "git did not exit cleanly (exit code 128)" means Git itself encountered a fatal error and the GUI is only reporting the exit code. Exit code 128 is Git's generic "fatal" signal, so the real diagnosis comes from reproducing the failing command in a terminal, reading the actual error message, and then fixing the specific repository, credential, or configuration issue that caused it.
What Exit Code 128 Means
When Git hits a fatal error, it prints a message starting with fatal: and exits with code 128. TortoiseGit captures the exit code but often truncates or hides the fatal: message in its dialog box. That is why the same error can mean dozens of different things: bad remote URL, expired credentials, corrupted repository, missing branch, permission denied, or lock file contention.
The TortoiseGit dialog is a symptom reporter, not a diagnostic tool. The fix always starts by running the command outside the GUI.
Step 1: Reproduce the Error in a Terminal
Open a terminal (Command Prompt, PowerShell, or Git Bash) in the same repository directory and run the operation that failed:
The terminal output will show the full fatal: message, which tells you what is actually wrong. Common examples:
Each of these has a different fix.
Step 2: Check for Lock Files
A stale lock file is one of the most common causes. If a previous Git operation crashed or was killed mid-operation, it may have left a .lock file that blocks subsequent operations.
If you find lock files and no Git process is currently running, delete them:
Only delete lock files when you are certain no other Git operation is active. Check Task Manager for running git.exe processes first.
Step 3: Verify Remote URL and Authentication
A large percentage of exit code 128 errors come from remote access failures. The remote URL may have changed, your token may have expired, or SSH key authentication may be misconfigured.
If you recently switched from password authentication to token-based authentication (GitHub deprecated passwords in 2021), TortoiseGit may still have the old password cached.
Step 4: Check Repository Integrity
If git status itself fails, the repository may be corrupted:
If git fsck reports errors, you have a corrupted repository. The recovery path depends on the type of corruption:
Step 5: Align TortoiseGit's Tool Configuration
TortoiseGit uses external Git and SSH executables. If it points to a different Git installation or SSH client than your terminal, the same repository can behave differently between the two.
Check these settings in TortoiseGit (Settings > General):
| Setting | What to Check |
| Git.exe Path | Must point to the same git.exe your terminal uses. Run where git to find it. |
| SSH Client | TortoiseGit defaults to TortoisePlink. If your keys are in OpenSSH format, switch to the Git-bundled ssh.exe. |
| Credential Helper | Should match what your terminal uses. Run git config credential.helper to check. |
A common scenario: your terminal uses Git for Windows' built-in OpenSSH, but TortoiseGit uses TortoisePlink, which reads Putty-format keys (.ppk) instead of OpenSSH keys. The terminal works fine, but TortoiseGit fails with exit code 128 because TortoisePlink cannot read your id_rsa file.
Systematic Troubleshooting Order
Work through these in sequence rather than guessing:
- Run the failing operation in a terminal and read the
fatal:message - Check for and remove stale
.lockfiles - Verify remote URLs with
git remote -v - Test authentication with
ssh -Torgit ls-remote - Run
git fsckto check repository integrity - Compare TortoiseGit's Git/SSH paths against your terminal's
- Re-clone as a last resort (only after backing up local work)
Common Pitfalls
- Debugging through the TortoiseGit dialog instead of reproducing the error in a terminal. The GUI hides the actual
fatal:message that contains the diagnosis. - Deleting
.lockfiles while another Git process is still running. This can corrupt the repository index. Check Task Manager first. - Assuming exit code 128 is a TortoiseGit-specific bug. It is a standard Git fatal error code. TortoiseGit is only the messenger.
- Re-cloning as the first troubleshooting step. This hides the root cause (expired token, bad SSH config, wrong remote URL) and the problem will recur.
- Using TortoisePlink with OpenSSH-format keys. Either convert your keys with PuTTYgen or switch TortoiseGit's SSH client to
ssh.exefrom Git for Windows. - Forgetting that Windows paths are case-insensitive but Git internals are not. A repository cloned on Linux with files differing only in case can cause fatal errors on Windows.
Summary
- Exit code 128 is Git's generic fatal error code. The actual cause is in the
fatal:message, which TortoiseGit often truncates. - Always reproduce the error in a terminal first to see the full message.
- The most common causes are stale lock files, expired credentials, wrong remote URLs, and mismatched Git/SSH tool paths between TortoiseGit and the terminal.
- Work through causes systematically: terminal reproduction, lock files, remote URL, authentication, repository integrity, tool configuration.
- Re-cloning should be the last resort, not the first step, because it hides the underlying problem.

