PyCharm更新GitHub凭证后推送仍失败,请求解决方法
Hey there, let's work through this push issue you're facing. The error mentions the old repository URL, so we'll tackle this from checking remote settings to updating credentials step by step:
1. Check & Update Your Local Repository's Remote URL
First, the most likely culprit is that your local project is still pointing to the old GitHub repository URL. Let's confirm and fix that:
- Open the terminal in PyCharm (bottom toolbar > Terminal) or open a system terminal and navigate to your project directory.
- Run this command to list current remote repositories:
git remote -v - If you see the
Old_Repository_urllisted underorigin, update it with your new repository URL using:
Replace the URL with your actual new GitHub repo address.git remote set-url origin https://github.com/your-new-username/your-repo-name.git
2. Update Local Git User Credentials
Since you changed your GitHub username and email, make sure your local Git config matches the new info:
- For the current project only, run these commands in the terminal:
git config user.name "Your New GitHub Username" git config user.email "your-new-github-email@example.com" - If you want this to apply to all your Git projects globally, add the
--globalflag:git config --global user.name "Your New GitHub Username" git config --global user.email "your-new-github-email@example.com"
3. Clear Git Credential Cache on Ubuntu 16.04
Ubuntu often caches Git credentials, so even if you updated settings in PyCharm, the system might still be using old credentials. Here's how to clear them:
- First, check which credential helper Git is using:
git config --global credential.helper - If it shows
libsecret(the default for Ubuntu):- You can use the graphical
seahorsetool (search for "Passwords and Keys" in Ubuntu's app menu) — look for entries related to GitHub, right-click, and delete them. - Or use terminal commands to delete the cached credential:
secret-tool delete host github.com
- You can use the graphical
- If it shows
cache:- Clear the cache immediately with:
git credential-cache exit
- Clear the cache immediately with:
4. Verify PyCharm Settings
Double-check a couple of things in PyCharm to ensure everything syncs:
- Go to
Settings > Version Control > Gitand confirm the Git executable path is correct (usually/usr/bin/giton Ubuntu). - Go to
Settings > Version Control, select your project, and check that the remoteoriginURL now shows your new repo address (it should update after you ran thegit remote set-urlcommand, but sometimes a quick restart of PyCharm helps).
Test the Push
After making these changes, try pushing your project again — either through PyCharm or by running git push origin main (or your branch name) in the terminal. If the terminal push works but PyCharm still has issues, restart PyCharm to refresh its cache.
内容的提问来源于stack exchange,提问作者Delosari




