How to Use Git Credential Helper for Secure Authentication
Use
git config --global credential.helper <helper-name> to set a credential helper that stores your Git credentials securely. This avoids repeated prompts for username and password when interacting with remote repositories.Syntax
The basic syntax to set a credential helper in Git is:
git config --global credential.helper <helper-name>: Sets the credential helper globally for all repositories.credential.helper: The name of the helper program or method Git uses to store credentials.- Common helpers include
cache,store, and platform-specific helpers likeosxkeychainorwincred.
bash
git config --global credential.helper <helper-name>
Example
This example sets Git to cache your credentials in memory for 15 minutes, so you don't have to enter your username and password repeatedly during that time.
bash
git config --global credential.helper 'cache --timeout=900' # Now when you push or pull, Git will ask for credentials once and cache them for 900 seconds (15 minutes).
Output
Configured credential helper to cache credentials for 900 seconds.
Common Pitfalls
Common mistakes when using Git credential helpers include:
- Using
storehelper without encryption, which saves passwords in plain text in your home directory. - Not specifying the helper globally or per repository, causing inconsistent behavior.
- Forgetting to install platform-specific helpers like
osxkeychainon macOS orwincredon Windows.
Always choose a helper that fits your security needs.
bash
git config --global credential.helper store # This saves credentials unencrypted in ~/.git-credentials, which is insecure. # Safer alternative on macOS: git config --global credential.helper osxkeychain
Quick Reference
| Credential Helper | Description | Platform |
|---|---|---|
| cache | Caches credentials in memory for a limited time | Linux, macOS |
| store | Stores credentials unencrypted on disk | All |
| osxkeychain | Uses macOS Keychain for secure storage | macOS |
| wincred | Uses Windows Credential Manager | Windows |
| manager-core | Cross-platform credential manager | Windows, macOS, Linux |
Key Takeaways
Set credential helper globally with git config to avoid repeated login prompts.
Use secure helpers like osxkeychain or manager-core instead of plain text store.
Cache helper temporarily stores credentials in memory for convenience.
Avoid storing passwords unencrypted with the store helper unless necessary.
Install platform-specific helpers for best security and integration.