Security
Git Credential Helper Setup
Configure Git credential helpers to avoid typing usernames and passwords repeatedly while keeping credentials secure.
- Developers who need to configure Git security and authentication
- Basic SSH concepts
- Command-line experience
- Poor key management leading to security leaks
- Not understanding signing policy causing verification failures
Overview
Typing usernames and passwords for every Git operation is tedious. Credential helpers cache or store credentials securely and provide them automatically.
Common Credential Helpers
| Helper | Storage | Best For |
|---|---|---|
cache | In-memory (configurable TTL) | Short-lived, secure |
osxkeychain | macOS Keychain | macOS users |
manager-core | Windows Credential Manager | Windows users |
libsecret | Linux Secret Service | Linux desktop users |
store | Plaintext disk file | ⚠️ Not recommended |
Configuration
macOS: osxkeychain
# Usually pre-installed with Git on macOS
git config --global credential.helper osxkeychain
# Verify
git config --global --get credential.helper
# Output: osxkeychain
The first operation will prompt for Keychain access — approve it and you won't be asked again.
Memory Cache
# Default 15-minute cache
git config --global credential.helper cache
# Custom timeout (seconds)
git config --global credential.helper "cache --timeout=3600"
# Cache for 1 hour
Best for short sessions — cache clears on reboot.
Linux: libsecret
# Install libsecret
sudo apt-get install libsecret-1-0 libsecret-1-dev
sudo make --directory=/usr/share/doc/git/contrib/credential/libsecret
# Configure
git config --global credential.helper /usr/share/doc/git/contrib/credential/libsecret/git-credential-libsecret
Per-Host Configuration
Use different helpers for different Git hosts:
# Global: osxkeychain
git config --global credential.helper osxkeychain
# Per-host: cache for GitLab
git config --global credential.https://gitlab.com.helper cache
Credential Context
Git matches credential contexts by URL. Common config:
# ~/.gitconfig
[credential]
helper = osxkeychain
[credential "https://github.com"]
username = your-github-username
[credential "https://gitlab.com"]
username = your-gitlab-username
Security Recommendations
- Avoid
storehelper: Stores credentials in plaintext — anyone with disk access can read them - HTTPS vs SSH: SSH keys are usually better for long-term use than HTTPS credentials
- Regular cleanup: Periodically review stored credentials and remove unused ones
- Environment isolation: Use different credential configs for work vs personal repos
Troubleshooting
Helper Not Working
# Debug: see which helper Git is trying to use
GIT_TRACE=1 git fetch
# Force a specific helper
git -c credential.helper=osxkeychain fetch
Clearing Cached Credentials
# Clear all credential cache
git credential-cache exit
# Or manually delete Keychain entries (macOS)
open /Applications/Utilities/Keychain\ Access.app
Continue Learning
security/ssh-key-management— SSH key managementsecurity/signing-advanced— Advanced commit signingsecurity/gpg-signing— GPG signing basics