Skip to content

Latest commit

 

History

History
124 lines (75 loc) · 8.06 KB

caching-your-github-credentials-in-git.md

File metadata and controls

124 lines (75 loc) · 8.06 KB
title redirect_from intro versions shortTitle
Caching your GitHub credentials in Git
/firewalls-and-proxies
/articles/caching-your-github-password-in-git
/github/using-git/caching-your-github-password-in-git
/github/using-git/caching-your-github-credentials-in-git
/github/getting-started-with-github/caching-your-github-credentials-in-git
/github/getting-started-with-github/getting-started-with-git/caching-your-github-credentials-in-git
If you're [cloning {% data variables.product.product_name %} repositories using HTTPS](/github/getting-started-with-github/about-remote-repositories), we recommend you use {% data variables.product.prodname_cli %} or a Git credential helper to authenticate and to remember your credentials.
fpt ghes ghec
*
*
*
Caching credentials

{% tip %}

Tip: If you clone {% data variables.product.product_name %} repositories using SSH, then you can authenticate using an SSH key instead of using other credentials. For information about setting up an SSH connection, see "AUTOTITLE."

{% endtip %}

{% data variables.product.prodname_cli %}

{% data variables.product.prodname_cli %} works cooperatively with Git on your command line. It helps you log in to {% data variables.product.product_name %}, and automatically stores your Git credentials for you. Choose HTTPS as your preferred protocol for Git operations and answer "yes" to the prompt asking if you would like to authenticate to Git with your {% data variables.product.product_name %} credentials.

  1. Install {% data variables.product.prodname_cli %} on macOS, Windows, or Linux.
  2. In the command line, enter gh auth login, then follow the prompts.
    • When prompted for your preferred protocol for Git operations, select HTTPS.
    • When asked if you would like to authenticate to Git with your {% data variables.product.product_name %} credentials, enter Y.

For more information about authenticating with {% data variables.product.prodname_cli %}, see gh auth login.

Git Credential Manager

Git Credential Manager (GCM) extends your Git installation. On Git's behalf, it helps you log in to {% data variables.product.product_name %}, including 2FA (two-factor authentication), and stores your credentials securely. Or, if you have manually created and stored a {% data variables.product.pat_generic %}, GCM can store that token securely, and provided it to {% data variables.product.product_name %} automatically when needed. In Git terms, GCM is an OAuth credential helper.

{% mac %}

  1. Install Git using Homebrew:

    brew install git
  2. Install GCM using Homebrew:

    brew install --cask git-credential-manager

For macOS, you don't need to run git config because GCM automatically configures Git for you.

{% data reusables.gcm-core.next-time-you-clone %}

Once you've authenticated successfully, your credentials are stored in the macOS keychain and will be used every time you clone an HTTPS URL. Git will not require you to type your credentials in the command line again unless you change your credentials.

{% endmac %}

{% windows %}

  1. Install Git for Windows, which includes GCM. For more information, see "Git for Windows releases" from its releases page.

We recommend always installing the latest version. At a minimum, install version 2.29 or higher, which is the first version offering OAuth support for GitHub.

{% data reusables.gcm-core.next-time-you-clone %}

Once you've authenticated successfully, your credentials are stored in the Windows credential manager and will be used every time you clone an HTTPS URL. Git will not require you to type your credentials in the command line again unless you change your credentials.


{% warning %}

Warning: Older versions of Git for Windows came with Git Credential Manager for Windows. This older product is no longer supported and cannot connect to GitHub via OAuth. We recommend you upgrade to the latest version of Git for Windows.

{% endwarning %}

{% warning %}

Warning: If you cached incorrect or outdated credentials in Credential Manager for Windows, Git will fail to access {% data variables.product.product_name %}. To reset your cached credentials so that Git prompts you to enter your credentials, access the Credential Manager in the Windows Control Panel under User Accounts > Credential Manager. Look for the {% data variables.product.product_name %} entry and delete it.

{% endwarning %}

{% endwindows %}

{% linux %}

For Linux, install Git and GCM, then configure Git to use GCM.

  1. Install Git from your distro's packaging system. Instructions will vary depending on the flavor of Linux you run.

  2. Install GCM. See the instructions in the GCM repo, as they'll vary depending on the flavor of Linux you run.

  3. Configure Git to use GCM. There are several backing stores that you may choose from, so see the GCM docs to complete your setup. For more information, see "GCM Linux."

{% data reusables.gcm-core.next-time-you-clone %}

Once you've authenticated successfully, your credentials are stored on your system and will be used every time you clone an HTTPS URL. Git will not require you to type your credentials in the command line again unless you change your credentials.

For more options for storing your credentials on Linux, see Credential Storage in Pro Git.

{% endlinux %}


For more information or to report issues with GCM, see the official GCM docs at "Git Credential Manager."

Other Git credential helpers

There are many Git credential helpers. Those which can authenticate via OAuth might well serve to authenticate to Git with your {% data variables.product.product_name %} credentials. Note that a Git installation can work with multiple credential helpers — it tries each in turn, until one gets it access. Thus you can perhaps add a credential helper for {% data variables.product.product_name %} to your existing helpers. Follow the instructions for the helper, and the Git credentials documentation, to configure the helper.

OAuth credential helpers will get you immediate access to your own repos. If you work with repos controlled by an organization, or with your forks and clones of those repos, then you must take an extra step. You must request that organization's approval for OAuth access by your helper, and the organization must approve access. Access is pre-authorized for {% data variables.product.prodname_cli %} and Git Credential Manager. If you use those tools, you do not need to request approval.

{% tip %}

Tip: If you use a Git command which requires access to an organization's repo (e.g. git fetch), and your helper seems to authenticate correctly, but the command fails with an error, then check that you have received the organization's approval for OAuth access by that app. The error may say something like:

remote: Repository not found.
fatal: repository 'https://github.com/ExampleUser/example-repo.git/' not found

{% endtip %}