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

GitHub本地连接配置报错求助:git push失败且ping github.com超时

Fixing Git Push Error: "ssh: Could not resolve hostname github.com:account" + Network Issues

Hey there, let's work through your problem step by step—this is a mix of a misconfigured remote repo URL and a potential network/DNS issue, so we'll tackle both head-on.

First: Fix the Misconfigured Remote Repository URL

The core error here is ssh: Could not resolve hostname github.com:account—this means your Git remote origin URL is formatted incorrectly. A valid SSH remote URL should look like git@github.com:YourUsername/YourRepoName.git, not something with github.com:account tacked on.

Here's how to fix it:

  1. First, check your current remote settings to confirm the bad URL:

    git remote -v
    

    You'll likely see an origin entry that ends with github.com:account instead of your actual repository path.

  2. Update the remote URL to the correct one:

    • If you prefer using SSH (make sure your SSH key is added to your GitHub account):
      git remote set-url origin git@github.com:YourActualGitHubUsername/YourRepoName.git
      
    • If you want to switch to HTTPS (often works better on restricted networks like mobile hotspots):
      git remote set-url origin https://github.com/YourActualGitHubUsername/YourRepoName.git
      

    Replace YourActualGitHubUsername with your real GitHub username, and YourRepoName with the name of the repository you're trying to push to.

Second: Resolve the "ping github.com Request Timeout" Issue

Even with the correct remote URL, if you can't ping GitHub, your network is having trouble resolving the domain. Try these fixes:

  • Switch to a public DNS server:

    1. On Windows 10, go to Settings > Network & Internet > Change adapter options.
    2. Right-click your mobile hotspot connection, select Properties.
    3. Find Internet Protocol Version 4 (TCP/IPv4) in the list, double-click it.
    4. Select Use the following DNS server addresses and enter:
      • Preferred DNS server: 8.8.8.8 (Google Public DNS)
      • Alternate DNS server: 8.8.4.4
    5. Click OK and test pinging github.com again.
  • Stick with HTTPS for remote access:
    HTTPS uses port 443, which is less likely to be blocked than SSH's port 22—this is especially common on mobile hotspot networks. If you switched to the HTTPS remote URL earlier, this might bypass the connectivity issue entirely.

Verify the Fix

After making these changes:

  1. Run git remote -v again to confirm the origin URL is correct.
  2. Try a test fetch to check connectivity:
    git fetch origin
    
  3. If using SSH, verify your key works with:
    ssh -T git@github.com
    
    You should see a message like Hi [YourUsername]! You've successfully authenticated, but GitHub does not provide shell access.

Once all that checks out, your git push -u origin master command should work as expected.

内容的提问来源于stack exchange,提问作者Shun Ishikawa

火山引擎 最新活动