Git

How to Save Username and Password in Git

February 28, 2023

This guide is part of the "Snippets" series. This series is focused on providing simple and accessible tutorials on various topics relating to development!


To save your username and password in Git, you can use Git's credential helper, which is a tool that helps Git to remember your credentials. The credential helper can store your credentials in various ways, including in memory, on disk, or using an external credential store.

Here's how to save your username and password in Git using the credential helper:

  1. Open a terminal or command prompt.
  2. Run the following command to enable credential caching:
git config --global credential.helper cache

This will enable Git's credential caching for the current user and will cache the credentials for 15 minutes by default.

  1. Run a Git command that requires authentication, such as cloning a repository.
  2. When prompted for your username and password, enter them as usual.
  3. Git will now cache your credentials for the specified period, and you won't be prompted for them again during that time.

If you want to store your credentials permanently, you can use a credential helper that stores your credentials on disk or in an external store, such as the macOS Keychain or the Windows Credential Store. Here's how to set up the macOS Keychain as your Git credential helper:

  1. Open a terminal.
  2. Run the following command to set the credential helper to use the macOS Keychain:
git config --global credential.helper osxkeychain
  1. Run a Git command that requires authentication, such as cloning a repository.
  2. When prompted for your username and password, enter them as usual.
  3. Git will now store your credentials in the macOS Keychain and will retrieve them automatically when needed.

For more information on credential helpers and how to configure them, see the Git documentation:


You might also like

The latest from the blog