The 'unable to connect to cache daemon' error occurs when Git cannot communicate with the credential cache daemon, typically due to socket permission issues, missing directories, or running Git as a different user than expected.
This error indicates that Git's credential cache helper cannot establish a connection to its background daemon process. The git-credential-cache system stores credentials in memory using a daemon process that communicates via a Unix domain socket. When you run Git operations that require authentication, the credential cache helper tries to connect to this daemon to retrieve or store credentials. If the socket file doesn't exist, has incorrect permissions, or the daemon isn't running, you'll see this "unable to connect to cache daemon" error. The daemon creates a socket file at `~/.cache/git/credential/socket` (or `~/.git-credential-cache/socket` on older systems). This socket must be owned by your user and have restricted permissions. Common scenarios that trigger this error include: 1. Running Git with sudo after initially configuring it as a regular user 2. Socket directory ownership issues from running Git as root 3. Missing socket directory or corrupted cache files 4. Network-mounted home directories that don't support Unix sockets
The most common cause is running Git with sudo, which creates the socket directory with root ownership. Fix the ownership to your user:
# Check current ownership of the socket directory
ls -la ~/.cache/git/credential/
# Fix ownership to your user
sudo chown -R $(whoami):$(whoami) ~/.cache/git/credential/
# Alternative if the directory is at the old location
sudo chown -R $(whoami):$(whoami) ~/.git-credential-cache/After fixing ownership, try your Git operation again without sudo.
If the socket file is corrupted or permissions are too complex to fix, delete the entire credential cache directory. Git will recreate it on the next credential operation:
# Remove the credential cache directory
rm -rf ~/.cache/git/credential/
# Or remove the old-style directory if it exists
rm -rf ~/.git-credential-cache/
# Verify it's gone
ls -la ~/.cache/git/credential/
# Should show "No such file or directory"The next time Git needs to cache credentials, it will recreate the directory with correct permissions.
If the directory doesn't exist, create it manually with the proper permissions:
# Create the directory with restricted permissions
mkdir -p ~/.cache/git/credential
chmod 700 ~/.cache/git/credential
# Verify the permissions
ls -la ~/.cache/git/
# Should show: drwx------ ... credentialThe directory must have 700 permissions (owner read/write/execute only) to satisfy Git's security requirements.
By default, the credential cache daemon times out after 900 seconds (15 minutes). Increase this if the daemon is shutting down too frequently:
# Check current credential helper configuration
git config --global credential.helper
# Set cache with longer timeout (8 hours = 28800 seconds)
git config --global credential.helper 'cache --timeout=28800'
# Or for even longer (1 week = 604800 seconds)
git config --global credential.helper 'cache --timeout=604800'Note that cached credentials are lost when the system restarts regardless of timeout.
If your home directory is on NFS or another network filesystem that doesn't support Unix domain sockets, specify a local socket path:
# Use a socket in /tmp (local filesystem)
git config --global credential.helper 'cache --socket=/tmp/git-credential-cache/socket'
# Create the directory with correct permissions
mkdir -p /tmp/git-credential-cache
chmod 700 /tmp/git-credential-cacheImportant: Using /tmp means credentials will be lost on reboot. For persistent storage on network filesystems, consider using git credential-store instead.
If cache continues to cause issues, switch to a more reliable credential helper:
Option 1: Git Credential Manager (recommended)
# Remove cache helper
git config --global --unset credential.helper
# Use Git Credential Manager
git config --global credential.helper managerOption 2: Store credentials in a file (less secure)
# Store credentials in plain text file
git config --global credential.helper store
# Credentials saved to ~/.git-credentialsOption 3: macOS Keychain
git config --global credential.helper osxkeychainOption 4: Disable credential caching entirely
git config --global --unset credential.helperOn some systems, the credential cache daemon might not be installed:
# Check if the daemon exists
which git-credential-cache--daemon
# If not found, try finding it
find /usr -name "git-credential-cache*" 2>/dev/nullOn Fedora/RHEL/CentOS:
# The daemon is in the git-daemon package
sudo dnf install git-daemonOn Ubuntu/Debian:
# Usually included with git, but check
dpkg -L git | grep credential-cacheOn Arch Linux:
# Part of the main git package
sudo pacman -S git### Understanding the Credential Cache Architecture
The git-credential-cache system consists of two components:
1. git-credential-cache - The credential helper that Git invokes
2. git-credential-cache--daemon - A background process that stores credentials in memory
When you first use credential caching, the helper starts the daemon automatically. The daemon:
- Creates a Unix domain socket at $XDG_CACHE_HOME/git/credential/socket
- Falls back to ~/.git-credential-cache/socket if the old directory exists
- Listens for credential requests from Git
- Stores credentials only in memory (never written to disk)
- Exits automatically after the configured timeout
### Socket Permission Security
Git enforces strict permissions on the socket directory:
# This error means permissions are too loose
fatal: The permissions on your socket directory are too loose
# Fix with
chmod 700 ~/.cache/git/credentialThe directory must have mode 0700 (rwx------) to prevent other users from potentially reading your cached credentials.
### Debugging Credential Cache Issues
# Run daemon in debug mode (foreground with verbose output)
git-credential-cache--daemon --debug ~/.cache/git/credential/socket
# In another terminal, test the connection
echo "protocol=https
host=github.com" | git credential-cache get
# Check if daemon is running
ps aux | grep git-credential-cache
# View Git configuration for credentials
git config --list --show-origin | grep credential### Windows Compatibility
The credential cache helper is NOT available on Windows because Windows doesn't support Unix domain sockets. If you see this error on Windows:
# You have cache configured somewhere - find it
git config -l --show-origin | grep credential.helper
# Remove the cache configuration
git config --global --unset credential.helper
# Use Windows Credential Manager instead
git config --global credential.helper manager### Multiple Git Installations
If you have multiple Git versions installed (e.g., system Git and Homebrew Git), they might use different socket paths:
# Check which git you're using
which git
git --version
# Ensure consistent credential helper across installations
git config --global credential.helper 'cache --socket=/home/$(whoami)/.cache/git/credential/socket'### Systemd User Service for Persistent Daemon
For Linux systems with systemd, you can create a user service to keep the daemon running:
# Create systemd user directory
mkdir -p ~/.config/systemd/user/
# Create service file
cat > ~/.config/systemd/user/git-credential-cache.service << 'EOF'
[Unit]
Description=Git Credential Cache Daemon
[Service]
ExecStart=/usr/lib/git-core/git-credential-cache--daemon %h/.cache/git/credential/socket
Restart=on-failure
[Install]
WantedBy=default.target
EOF
# Enable and start the service
systemctl --user enable git-credential-cache
systemctl --user start git-credential-cache### SSH vs HTTPS
If credential cache continues to be problematic, consider switching to SSH authentication which doesn't require credential caching:
# Generate SSH key
ssh-keygen -t ed25519 -C "[email protected]"
# Add to SSH agent (runs once per session)
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
# Change remote to SSH
git remote set-url origin [email protected]:user/repo.gitwarning: BOM detected in file, this may cause issues
UTF-8 Byte Order Mark (BOM) detected in file
fatal: Server does not support --shallow-exclude
Server does not support --shallow-exclude
warning: filtering out blobs larger than limit
Git partial clone filtering large blobs warning
fatal: Server does not support --shallow-since
Server does not support --shallow-since in Git
kex_exchange_identification: Connection closed by remote host
Connection closed by remote host when connecting to Git server