Skip to content

credential Git Command Guide

The git credential command retrieves, stores, or erases credentials (username and password) for remote Git repositories. It provides a standardized interface for credential helpers and is typically used internally by Git operations.

Terminal window
git credential <subcommand> [<options>]
OptionDescription
-h, —helpDisplay help information
-c, —config =Set configuration key/value
SubcommandDescription
getReturn credential for given parameters
storeStore given credential
eraseRemove credential from store
NameDescription
protocolProtocol to use (http, https)
hostRemote host name
pathPath within remote repository
usernameUser name
passwordUser password
Terminal window
echo "protocol=https
host=github.com
path=user/repo" | git credential get

Retrieves stored username and password for GitHub.

Terminal window
echo "protocol=https
host=github.com
username=johndoe
password=secret" | git credential store

Saves credentials to the credential store.

Terminal window
echo "protocol=https
host=github.com
username=johndoe" | git credential erase

Removes credentials for the specified user from store.

Terminal window
git config --global credential.helper store

Configures Git to use the store helper which uses git credential for storage.

How do I store Git credentials for remote access?

Section titled “How do I store Git credentials for remote access?”

To store Git credentials for remote access, use a credential helper that uses:

Terminal window
git credential store

To erase stored Git credentials, run:

Terminal window
echo "protocol=https
host=hostname
username=username" | git credential erase

To retrieve stored credentials, execute:

Terminal window
echo "protocol=https
host=hostname
path=path" | git credential get

Git provides several credential helpers including cache, store, and third-party helpers for integration with password managers or system keychains.

To configure a credential helper, use:

Terminal window
git config --global credential.helper <helper-name>

Applications of the git credential command

Section titled “Applications of the git credential command”
  1. Providing credentials for HTTPS authentication with remote repositories
  2. Integrating with password managers and system keychains
  3. Supporting SSO and OAuth authentication flows
  4. Managing multiple identities across different hosting services
  5. Automating credential handling in CI/CD pipelines
  6. Secure storage and retrieval of repository access tokens