How to fix fatal: Operation cancelled in Git
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)- Set GPG_TTY environment variable
- Restart the GPG agent
- Configure pinentry for your environment
- Check and renew expired GPG keys
# Add to ~/.bashrc, ~/.zshrc, or ~/.profileexport 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
- 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
- Credential helper configuration conflict between system and global settings
- Git Credential Manager timeout waiting for authentication
- Network connectivity issues or unstable connection
- Git hosting service experiencing an outage
- Proxy or firewall blocking the connection
- User dismissed the GPG passphrase or credential prompt
- Version mismatch between GPG and pinentry programs
How to fix "fatal: Operation cancelled"
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:
# Add to ~/.bashrc, ~/.zshrc, or ~/.profile
export GPG_TTY=$(tty)Apply immediately:
source ~/.bashrc # or ~/.zshrcFor 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:
echo $GPG_TTY
# Should output something like /dev/pts/0If GPG signing suddenly stopped working, restart the GPG agent:
# Kill the running GPG agent
gpgconf --kill gpg-agent
# The agent will restart automatically on next GPG operationTest signing works:
echo "test" | gpg --clearsign
# If this prompts for your passphrase and succeeds, GPG is workingIf the test fails, the issue is with your GPG configuration, not Git.
If GPG cannot show a passphrase prompt, configure the appropriate pinentry program:
For terminal-only environments (SSH, tmux):
# Edit ~/.gnupg/gpg-agent.conf
echo "pinentry-program /usr/bin/pinentry-tty" >> ~/.gnupg/gpg-agent.conf
# Restart the agent
gpgconf --kill gpg-agentFor macOS with GUI:
# 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-agentFor Linux with GUI:
# 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-agentExpired GPG keys will cause signing to fail:
Check your key status:
# List your keys with expiration dates
gpg --list-secret-keys --keyid-format SHORT
# Look for [expired] or check the expiration dateExtend an expired key:
# 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
saveVerify Git is using the correct key:
# Check configured signing key
git config --global user.signingkey
# Set if not configured
git config --global user.signingkey KEYIDOn Windows, credential helper conflicts can cause TaskCanceledException errors:
Check current configuration:
# View system-level config
git config --list --system | Select-String credential
# View global-level config
git config --list --global | Select-String credentialFix by using consistent credential helper:
# 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-coreClear cached credentials if needed:
# Open Credential Manager
control /name Microsoft.CredentialManager
# Find and remove entries starting with "git:"If the error occurs during push, pull, or clone operations:
Test network connectivity:
# Test connection to GitHub
ssh -T git@github.com
# Or for HTTPS
curl -I https://github.comCheck 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:
# 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.proxyIf you need to commit urgently and can't fix GPG issues immediately:
Disable for a single commit:
git commit --no-gpg-sign -m "Your commit message"Disable globally (temporary workaround):
git config --global commit.gpgsign false
# Re-enable later with:
git config --global commit.gpgsign trueNote: 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:
# 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:
# 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:
# 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:
# 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:
# 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:
# 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)
# Check GCM version
git credential-manager --version
# Reconfigure GCM
git credential-manager unconfigure
git credential-manager configure
# Run diagnostics
git credential-manager diagnoseFrequently 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
- 📚Git Official Documentation
- 💬
- 💬
- 💬Ask Ubuntu - GPG2 signing failed: Operation cancelled(Stack Overflow)
- 💬Stack Overflow - Git error: gpg failed to sign data(Stack Overflow)
- 🐙
- 📖Git Documentation - Signing Your Work(Official Docs)