Skip to content

Git credential helpers quick reference ​

Helper types comparison ​

HelperStorage typeSecurity levelBest use case
cacheIn-memory daemon socketHigh (ephemeral, zero disk writes)CI runners, ephemeral containers, short sessions
storePlaintext file (~/.git-credentials)Low (unencrypted disk file)Air-gapped machines, test environments
libsecretLinux Secret Service API (Keyring)High (OS keychain encryption)Linux developer workstations
osxkeychainmacOS KeychainHigh (OS keychain encryption)macOS developer workstations
wincredWindows Credential ManagerHigh (OS keychain encryption)Windows developer workstations
Custom script (!...)External vault, API, or JWT generatorHigh (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 exit

2. 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-credentials

3. 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 approve

Manual protocol debugging ​

Query credentials (fill) ​

bash
printf "protocol=https\nhost=git.local.sneakysquid.xyz\n\n" | git credential fill

Store credentials (approve) ​

bash
printf "protocol=https\nhost=git.local.sneakysquid.xyz\nusername=bot\npassword=token123\n\n" | git credential approve

Purge credentials (reject) ​

bash
printf "protocol=https\nhost=git.local.sneakysquid.xyz\n\n" | git credential reject

Security 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://|')"

Git Master — Git Reference for Every Skill Level