无法从PC推送至GitHub:SSL证书问题求助
Hey there! Since you're a Git/GitHub newbie and previously could push code without issues, this sudden SSL error is likely due to a change in your network or system environment—like a new router with SSL inspection, antivirus software intercepting connections, or a subtle Git config tweak. Let's walk through simple, step-by-step solutions tailored for your Windows 10 + Git Bash setup:
1. First: Test if SSL Verification is the Culprit (Temporary Fix)
This is a quick check to confirm the issue ties to SSL certificates. Don't use this long-term (it disables important security checks), but it'll help narrow things down:
- Run this command in Git Bash:
git config --global http.sslVerify false - Try pushing your code again with
git push. If it works, you've confirmed the problem is SSL certificate-related. - Remember to re-enable SSL verification afterward to keep your connections secure:
git config --global http.sslVerify true
2. Import GitHub's Official Certificate (Recommended Long-Term Fix)
This tells Git to explicitly trust GitHub's valid certificate, resolving the chain mismatch:
- Export GitHub's certificate:
- Open your browser, go to github.com. Click the lock icon in the address bar → "Certificate (Valid)" → "Details" tab → "Copy to File..."
- Choose "Base64 encoded X.509 (.CER)" as the format, save it as
github.crtsomewhere easy to find (like your Documents folder).
- Configure Git to use the certificate:
- In Git Bash, run this command (replace the path with where you saved
github.crt):git config --global http.sslCAInfo "C:/Users/YourUsername/Documents/github.crt" - Try pushing again. This should fix the issue without sacrificing security.
- In Git Bash, run this command (replace the path with where you saved
3. Check for Antivirus/Firewall SSL Interception
Many antivirus tools or home routers use "SSL scanning" which inserts a self-signed certificate into your connection. This confuses Git because it doesn't recognize the certificate:
- Temporarily disable SSL scanning features in your antivirus software (look for terms like "web protection" or "SSL inspection").
- If you have a custom router, check its settings for any SSL filtering options and disable them temporarily.
- Try pushing again. If it works, add github.com to your antivirus/router's trusted sites list to keep protection enabled while avoiding the error.
4. Switch to SSH Protocol (Alternative Fix)
If HTTPS keeps giving you trouble, switching to SSH is a reliable alternative—and it avoids password prompts once set up:
- Generate an SSH key:
- In Git Bash, run this (replace with your GitHub email):
ssh-keygen -t ed25519 -C "your_email@example.com" - Press Enter three times to accept default settings (no passphrase unless you want an extra layer of security).
- In Git Bash, run this (replace with your GitHub email):
- Add the key to GitHub:
- Open the public key file in Git Bash:
cat ~/.ssh/id_ed25519.pub - Copy the entire output (starts with
ssh-ed25519). - Go to GitHub → Click your profile picture → Settings → SSH and GPG keys → New SSH key.
- Paste the key, give it a name (like "Windows Git Bash"), and save.
- Open the public key file in Git Bash:
- Update your remote repository URL:
- Replace the HTTPS URL with SSH in Git Bash:
git remote set-url origin git@github.com:myusername/my-repo.git - Now try
git pushagain—this should work without SSL issues.
- Replace the HTTPS URL with SSH in Git Bash:
内容的提问来源于stack exchange,提问作者Shadow43375

