If password authentication (over HTTPS) for Git operations has been disabled, as GitHub and many other Git hosting services have done for security reasons, you cannot use your username and password directly to clone a repository or perform other Git operations over HTTPS. This measure is intended to enhance security by preventing the use of potentially insecure passwords and encouraging the use of more secure methods, such as SSH keys or personal access tokens (PATs).
When prompted for a username, enter your GitHub (or respective service) username. When prompted for a password, enter the PAT you generated instead of your account password.
Or, for a more secure storage option that integrates with your system's keychain:
Using Personal Access Tokens (PATs)
A Personal Access Token (PAT) can serve as a secure alternative to password authentication. Here's how you can use a PAT for cloning a repository and other Git operations:- Generate a Personal Access Token:
- Go to your Git hosting service's settings (e.g., GitHub, GitLab, Bitbucket).
- Find the section for creating a PAT, which is usually under Developer Settings or Access Tokens.
- Select the scopes or permissions you want the token to have. For cloning a private repository, you usually need "repo" or equivalent permissions.
- Generate the token and make sure to copy it; you won't be able to see it again.
- Use the PAT as Your Password: When cloning a repository or when prompted for your username and password during Git operations, use your username as normal, but use the PAT as your password.
git clone https://github.com/username/repository-name.git
Configuring Git to Store the PAT
To avoid entering the PAT every time, you can use a credential helper to store your credentials securely. Git has support for credential helpers that store your tokens securely in your system's keychain. To use a credential helper with Git:git config --global credential.helper store
- On macOS:
git config --global credential.helper osxkeychain
- On Windows:
git config --global credential.helper wincred
- On Linux, you might use
libsecret
:git config --global credential.helper '/usr/share/doc/git/contrib/credential/libsecret/git-credential-libsecret'