Git 1.9.5版本可执行pull但无法push/fetch问题求助
Hey there, sorry to hear you're hitting this frustrating issue—pull works fine, but push/fetch suddenly stopped? Let's walk through the most likely fixes, since this usually ties back to authentication, remote config, network quirks, or even your older Git version's limitations.
1. Check Authentication First (Most Common Culprit)
Pull might work anonymously or with cached credentials, but push/fetch often requires valid, up-to-date auth.
- Verify remote URLs: Run
git remote -vto make sure your push and pull URLs match. Sometimes a misconfiguration (e.g., pull uses HTTPS but push uses SSH, or vice versa) can break authentication. If they don't align, update the push URL withgit remote set-url origin <correct-repo-url>. - Refresh HTTPS credentials: Git 1.9.5's credential cache can expire or get corrupted.
- On Windows: Run
git config --global credential.helper wincred—next time you push, it'll prompt for your username/password again. - On Linux/macOS: Use
git config --global credential.helper cacheto reset the cache, or manually delete stored credentials (e.g., in macOS Keychain, search for entries labeled "git").
- On Windows: Run
- Troubleshoot SSH keys: If you're using SSH, test the connection with
ssh -T git@<your-remote-host>(replace with your repo host like github.com). If you get an error:- Check key permissions: Run
chmod 700 ~/.sshandchmod 600 ~/.ssh/id_rsa—strict permissions are required for SSH to work. - Regenerate and re-add the key: If your key is expired or invalid, create a new one with
ssh-keygen -t rsa -b 4096and add the public key to your remote repo's SSH settings.
- Check key permissions: Run
2. Fix Remote Branch Tracking Issues
Sometimes the link between your local branch and the remote branch breaks unexpectedly.
- Check tracking status: Run
git branch -vv—look for the remote branch next to your local branch (e.g.,* master abc123 [origin/master]). If it's missing or shows an error, re-set the tracking:git branch --set-upstream-to=origin/<remote-branch-name> <local-branch-name> - Validate remote existence: Run
git remote show origin—if you get "remote origin does not exist", re-add the remote withgit remote add origin <your-repo-url>.
3. Rule Out Network/Firewall Problems
A sudden change in your network (like a new firewall rule or proxy) can block push/fetch traffic even if pull works.
- Test port connectivity: For SSH, run
telnet <your-remote-host> 22; for HTTPS, runtelnet <your-remote-host> 443. If the connection fails, your network is likely blocking that port—contact your admin or switch protocols (SSH ↔ HTTPS) to work around it. - Clear invalid proxy settings: If Git was using a proxy that's now offline, remove it:
git config --global --unset http.proxy git config --global --unset https.proxy
4. Work Around Git 1.9.5's Limitations
Git 1.9.5 is pretty old (released in 2014), so it might not support modern repo security features.
- Enable legacy SSH algorithms: If your remote repo disabled older algorithms like RSA SHA-1 (common on platforms like GitHub), add this to your
~/.ssh/configfile:Host <your-remote-host> HostkeyAlgorithms +ssh-rsa PubkeyAcceptedAlgorithms +ssh-rsa - Consider upgrading (if possible): While you might be stuck on 1.9.5 for compatibility, upgrading to a newer version (even 2.x) would fix many known auth and protocol issues.
If none of these work, share the exact error message you get when running git push or git fetch—that'll help narrow down the problem even more!
内容的提问来源于stack exchange,提问作者Andre Rubnikowich

