GitHub本地连接配置报错求助:git push失败且ping github.com超时
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:
First, check your current remote settings to confirm the bad URL:
git remote -vYou'll likely see an origin entry that ends with
github.com:accountinstead of your actual repository path.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
YourActualGitHubUsernamewith your real GitHub username, andYourRepoNamewith the name of the repository you're trying to push to.- If you prefer using SSH (make sure your SSH key is added to your GitHub account):
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:
- On Windows 10, go to Settings > Network & Internet > Change adapter options.
- Right-click your mobile hotspot connection, select Properties.
- Find Internet Protocol Version 4 (TCP/IPv4) in the list, double-click it.
- 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
- Preferred DNS server:
- 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:
- Run
git remote -vagain to confirm the origin URL is correct. - Try a test fetch to check connectivity:
git fetch origin - If using SSH, verify your key works with:
You should see a message likessh -T git@github.comHi [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




