How to Bypass Password Authentication in Git over HTTPS
When accessing remote repositories using Git, entering your password every time via HTTPS can be tedious. This article introduces methods to bypass password authentication.
Method 1: Using Git Credential Helper
Git has a feature to cache credentials, which you can use to avoid entering your password repeatedly.
1. Configuring Credential Helper
Run the following command to have Git remember your credentials.
# Cache credentials (retained for 15 minutes by default)
git config --global credential.helper cache
# Set cache timeout (1 hour)
git config --global credential.helper 'cache --timeout=3600'
Alternatively, you can use an credential manager tailored to your OS.
# Windows (Git Credential Manager for Windows)
git config --global credential.helper manager
# macOS (Using Keychain)
git config --global credential.helper osxkeychain
# Linux (Using libsecret)
git config --global credential.helper store
2. Enter Credentials Once
After configuration, enter your password once when accessing the Git remote repository, and subsequent entries will no longer be necessary.
Method 2: Using SSH Keys (Recommended)
You can bypass password entry more securely by using SSH keys instead of HTTPS authentication.
1. Generate an SSH Key
ssh-keygen -t ed25519 -C "your_email@example.com"
2. Register the Public Key to the Remote Repository
Omitted
3. Configure SSH Connection
git remote set-url origin git@github.com:user/repository.git
Conclusion
Entering a password every time when accessing Git repositories via HTTPS is a hassle, but it can be avoided by configuring a Credential Helper, using a PAT (Personal Access Token), or leveraging SSH keys. In particular, using SSH keys is superior in terms of security, so we recommend switching to SSH authentication if possible.