How to fix fatal: Operation cancelled in Git

GitINTERMEDIATEMEDIUMUpdated Dec 6, 2025· 185 views

The 'Operation cancelled' error in Git typically occurs when GPG signing fails due to terminal issues, when the credential helper times out, or when a network operation is interrupted. The fix depends on whether the error stems from GPG configuration, authentication, or connectivity problems.

Quick fix

Fixes fatal: Operation cancelled

# Add to ~/.bashrc, ~/.zshrc, or ~/.profile
export GPG_TTY=$(tty)
  1. Set GPG_TTY environment variable
  2. Restart the GPG agent
  3. Configure pinentry for your environment
  4. Check and renew expired GPG keys
git — error
# Add to ~/.bashrc, ~/.zshrc, or ~/.profile
export GPG_TTY=$(tty)
fatal: Operation cancelled

What this error means

This error indicates that Git was unable to complete an operation because it was cancelled before finishing. The cancellation can happen for several different reasons: 1. **GPG Signing Failed**: When Git is configured to sign commits with GPG and the signing process cannot complete—typically because GPG cannot access the terminal to prompt for your passphrase. 2. **Credential Helper Timeout**: On Windows, the Git Credential Manager may time out while waiting for authentication, especially when there are configuration conflicts between system and global credential helper settings. 3. **Network Operation Interrupted**: A push, pull, fetch, or clone operation may be cancelled due to network instability, proxy issues, or the remote server being unavailable. 4. **User Cancellation**: The user manually cancelled the operation (Ctrl+C) or dismissed an authentication/passphrase prompt. The full error message often provides more context. For example, `gpg: signing failed: Operation cancelled` indicates a GPG problem, while `fatal: TaskCanceledException encountered` (on Windows) points to credential helper issues.

Typical symptoms

  • Git commit fails with 'gpg: signing failed: Operation cancelled'
  • Git push or pull hangs for ~20 seconds then fails with 'Operation cancelled'
  • Commands work outside of tmux/screen but fail inside terminal multiplexers
  • Git operations suddenly stop working after system updates
  • Error appears when trying to sign commits with GPG
  • Windows shows 'TaskCanceledException encountered' during push/pull
  • Operations fail only when GPG signing is enabled
  • Credential prompt never appears before operation times out

Common causes

  1. GPG_TTY environment variable not set (common in tmux/screen sessions)
  2. Pinentry program cannot access the terminal for passphrase entry
  3. GPG key has expired or is not available
  4. Credential helper configuration conflict between system and global settings
  5. Git Credential Manager timeout waiting for authentication
  6. Network connectivity issues or unstable connection
  7. Git hosting service experiencing an outage
  8. Proxy or firewall blocking the connection
  9. User dismissed the GPG passphrase or credential prompt
  10. Version mismatch between GPG and pinentry programs

How to fix "fatal: Operation cancelled"

1Set GPG_TTY environment variable

If the error mentions GPG signing, the most common fix is setting the GPG_TTY variable so GPG can access your terminal:

Add to your shell configuration:

bash
# Add to ~/.bashrc, ~/.zshrc, or ~/.profile
export GPG_TTY=$(tty)

Apply immediately:

bash
source ~/.bashrc  # or ~/.zshrc

For tmux users, ensure this is in a file that's sourced for non-login shells (like ~/.bashrc for Bash, not just ~/.bash_profile).

Verify it's set:

bash
echo $GPG_TTY
# Should output something like /dev/pts/0
2Restart the GPG agent

If GPG signing suddenly stopped working, restart the GPG agent:

bash
# Kill the running GPG agent
gpgconf --kill gpg-agent

# The agent will restart automatically on next GPG operation

Test signing works:

bash
echo "test" | gpg --clearsign

# If this prompts for your passphrase and succeeds, GPG is working

If the test fails, the issue is with your GPG configuration, not Git.

3Configure pinentry for your environment

If GPG cannot show a passphrase prompt, configure the appropriate pinentry program:

For terminal-only environments (SSH, tmux):

bash
# Edit ~/.gnupg/gpg-agent.conf
echo "pinentry-program /usr/bin/pinentry-tty" >> ~/.gnupg/gpg-agent.conf

# Restart the agent
gpgconf --kill gpg-agent

For macOS with GUI:

bash
# Install pinentry-mac
brew install pinentry-mac

# Configure GPG to use it
echo "pinentry-program $(which pinentry-mac)" >> ~/.gnupg/gpg-agent.conf

# Restart the agent
killall gpg-agent

For Linux with GUI:

bash
# Use the GTK or Qt pinentry
echo "pinentry-program /usr/bin/pinentry-gtk-2" >> ~/.gnupg/gpg-agent.conf
# or
echo "pinentry-program /usr/bin/pinentry-qt" >> ~/.gnupg/gpg-agent.conf

gpgconf --kill gpg-agent
4Check and renew expired GPG keys

Expired GPG keys will cause signing to fail:

Check your key status:

bash
# List your keys with expiration dates
gpg --list-secret-keys --keyid-format SHORT

# Look for [expired] or check the expiration date

Extend an expired key:

bash
# Edit the key (replace KEYID with your key ID)
gpg --edit-key KEYID

# At the gpg> prompt:
expire
# Enter new expiration (e.g., "1y" for 1 year)
# Save and quit
save

Verify Git is using the correct key:

bash
# Check configured signing key
git config --global user.signingkey

# Set if not configured
git config --global user.signingkey KEYID
5Fix Windows credential helper configuration

On Windows, credential helper conflicts can cause TaskCanceledException errors:

Check current configuration:

powershell
# View system-level config
git config --list --system | Select-String credential

# View global-level config
git config --list --global | Select-String credential

Fix by using consistent credential helper:

powershell
# Option 1: Use wincred (older, simpler)
git config --global credential.helper wincred

# Option 2: Remove conflicting system setting
git config --system --unset credential.helper

# Option 3: Use the newer Git Credential Manager
git config --global credential.helper manager-core

Clear cached credentials if needed:

powershell
# Open Credential Manager
control /name Microsoft.CredentialManager

# Find and remove entries starting with "git:"
6Check network connectivity and service status

If the error occurs during push, pull, or clone operations:

Test network connectivity:

bash
# Test connection to GitHub
ssh -T git@github.com

# Or for HTTPS
curl -I https://github.com

Check service status:
- GitHub: [githubstatus.com](https://www.githubstatus.com/)
- GitLab: [status.gitlab.com](https://status.gitlab.com/)
- Bitbucket: [bitbucket.status.atlassian.com](https://bitbucket.status.atlassian.com/)

If using a proxy:

bash
# Configure proxy settings
git config --global http.proxy http://proxy.example.com:8080
git config --global https.proxy https://proxy.example.com:8080

# Or unset if proxy is causing issues
git config --global --unset http.proxy
git config --global --unset https.proxy
7Temporarily disable GPG signing

If you need to commit urgently and can't fix GPG issues immediately:

Disable for a single commit:

bash
git commit --no-gpg-sign -m "Your commit message"

Disable globally (temporary workaround):

bash
git config --global commit.gpgsign false

# Re-enable later with:
git config --global commit.gpgsign true

Note: This is a workaround, not a fix. If your organization requires signed commits, you should resolve the underlying GPG issue.

Advanced notes

### Debugging GPG Issues

Enable verbose output to understand what's failing:

bash
# Debug Git's GPG interaction
GIT_TRACE=1 git commit -m "test"

# Debug GPG directly
gpg --verbose --sign test.txt

### Multiple GPG Installations (Windows)

On Windows, you may have multiple GPG installations (Git for Windows, Gpg4win, WSL). Ensure Git uses the correct one:

bash
# Check which GPG Git is using
git config --global gpg.program

# Set explicitly if needed
git config --global gpg.program "C:\Program Files\Git\usr\bin\gpg.exe"

# Or for Gpg4win
git config --global gpg.program "C:\Program Files (x86)\GnuPG\bin\gpg.exe"

### GPG Agent Caching

Configure GPG agent to cache your passphrase longer:

bash
# Edit ~/.gnupg/gpg-agent.conf
default-cache-ttl 3600       # Cache for 1 hour
max-cache-ttl 86400          # Maximum 24 hours

# Restart agent
gpgconf --kill gpg-agent

### SSH Agent Issues

If using SSH and the operation is cancelled during authentication:

bash
# Check if SSH agent is running
ssh-add -l

# Start SSH agent if needed
eval "$(ssh-agent -s)"

# Add your key
ssh-add ~/.ssh/id_ed25519

### WSL-Specific Issues

When using Git in WSL with GPG:

bash
# Ensure GPG_TTY is set in WSL
echo 'export GPG_TTY=$(tty)' >> ~/.bashrc

# If using Windows GPG from WSL
export GPG_TTY=$(tty)
gpg-connect-agent updatestartuptty /bye

### Version Compatibility

Ensure your GPG and pinentry versions are compatible:

bash
# Check versions
gpg --version
pinentry --version

# Update if needed (Ubuntu/Debian)
sudo apt update && sudo apt upgrade gnupg pinentry-curses

# Update on macOS
brew upgrade gnupg pinentry-mac

### Credential Manager Diagnostics (Windows)

powershell
# Check GCM version
git credential-manager --version

# Reconfigure GCM
git credential-manager unconfigure
git credential-manager configure

# Run diagnostics
git credential-manager diagnose

Frequently asked questions

What does "fatal: Operation cancelled" mean?
This error indicates that Git was unable to complete an operation because it was cancelled before finishing. The cancellation can happen for several different reasons: 1. GPG Signing Failed: When Git is configured to sign commits with GPG and the signing process cannot complete—typically because GPG cannot access the terminal to prompt for your passphrase.
How do I fix "fatal: Operation cancelled"?
The 'Operation cancelled' error in Git typically occurs when GPG signing fails due to terminal issues, when the credential helper times out, or when a network operation is interrupted. The fix depends on whether the error stems from GPG configuration, authentication, or connectivity problems.
What causes "fatal: Operation cancelled"?
GPG_TTY environment variable not set (common in tmux/screen sessions) Pinentry program cannot access the terminal for passphrase entry GPG key has expired or is not available
Is the "fatal: Operation cancelled" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading