Appearance
Git credential helpers quick reference
Helper types comparison
| Helper | Storage type | Security level | Best use case |
|---|---|---|---|
cache | In-memory daemon socket | High (ephemeral, zero disk writes) | CI runners, ephemeral containers, short sessions |
store | Plaintext file (~/.git-credentials) | Low (unencrypted disk file) | Air-gapped machines, test environments |
libsecret | Linux Secret Service API (Keyring) | High (OS keychain encryption) | Linux developer workstations |
osxkeychain | macOS Keychain | High (OS keychain encryption) | macOS developer workstations |
wincred | Windows Credential Manager | High (OS keychain encryption) | Windows developer workstations |
Custom script (!...) | External vault, API, or JWT generator | High (JIT rotation, no persistence) | Enterprise CI/CD, Kubernetes pods |
Configuration commands
1. In-memory cache
bash
# Set cache with 1-hour timeout
git config --global credential.helper "cache --timeout=3600"
# Set cache with custom socket path
git config --global credential.helper "cache --timeout=1800 --socket=/tmp/git-cache.sock"
# Terminate running cache daemon
git credential-cache exit2. Plaintext store (with permission hardening)
bash
# Configure store helper
git config --global credential.helper "store --file ~/.git-credentials"
# Restrict file permissions
touch ~/.git-credentials && chmod 600 ~/.git-credentials3. Domain-scoped helper
bash
# Scope helper to a specific internal Forgejo instance
git config --global credential."https://git.local.sneakysquid.xyz".helper "store --file=/secrets/forgejo.creds"
# Scope helper to a specific repository path
git config --global credential."https://github.com/my-org/private-repo.git".helper "!/usr/local/bin/vault-helper"CI/CD runner one-liners
Direct header injection (zero disk storage)
bash
# Pass token per command
git -c http.extraHeader="Authorization: token $FORGEJO_TOKEN" clone https://git.local.sneakysquid.xyz/hermes/git-master.git
# Set global header for single host
git config --global http."https://git.local.sneakysquid.xyz/".extraHeader "Authorization: token $FORGEJO_TOKEN"Pre-populating credentials in memory
bash
# Seed cache without user interaction
printf "protocol=https\nhost=git.local.sneakysquid.xyz\nusername=oauth2\npassword=%s\n\n" "$FORGEJO_TOKEN" | git credential approveManual protocol debugging
Query credentials (fill)
bash
printf "protocol=https\nhost=git.local.sneakysquid.xyz\n\n" | git credential fillStore credentials (approve)
bash
printf "protocol=https\nhost=git.local.sneakysquid.xyz\nusername=bot\npassword=token123\n\n" | git credential approvePurge credentials (reject)
bash
printf "protocol=https\nhost=git.local.sneakysquid.xyz\n\n" | git credential rejectSecurity audit one-liners
bash
# Find plaintext tokens in local repository remotes
git config --local --get-regexp '^remote\..*\.url$' | grep -E 'https?://[^:]+:[^@]+@'
# Find plaintext tokens in global git config
git config --global --get-regexp '^remote\..*\.url$' | grep -E 'https?://[^:]+:[^@]+@'
# Remove hardcoded token from origin remote
git remote set-url origin "$(git remote get-url origin | sed -E 's|https://[^@]+@|https://|')"