You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

PyCharm更新GitHub凭证后推送仍失败,请求解决方法

Fixing Push Authentication Failed with Old GitHub Repository URL in PyCharm (Ubuntu 16.04)

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_url listed under origin, update it with your new repository URL using:
    git remote set-url origin https://github.com/your-new-username/your-repo-name.git
    
    Replace the URL with your actual new GitHub repo address.

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 --global flag:
    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 seahorse tool (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
      
  • If it shows cache:
    • Clear the cache immediately with:
      git credential-cache exit
      

4. Verify PyCharm Settings

Double-check a couple of things in PyCharm to ensure everything syncs:

  • Go to Settings > Version Control > Git and confirm the Git executable path is correct (usually /usr/bin/git on Ubuntu).
  • Go to Settings > Version Control, select your project, and check that the remote origin URL now shows your new repo address (it should update after you ran the git remote set-url command, 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

火山引擎 最新活动