You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows系统下使用Git命令行上传项目至GitHub失败求助

Hey there, let's work through fixing this Git push issue step by step—uploading projects to GitHub from the Windows command line can throw unexpected hurdles, even for folks who’ve done it before. Let’s break down the most common fixes:

First: Double-Check Your Git Basics

1. Verify Your Git User Configuration

GitHub needs to know who you are to accept your pushes. Open Git Bash or Command Prompt and run these commands (replace with your own GitHub username and email):

git config --global user.name "YourGitHubUsername"
git config --global user.email "your-github-email@example.com"

If you skip this, GitHub will reject your commits outright.

2. Pick the Right Authentication Method (SSH vs HTTPS)

Option 1: HTTPS (Quick Setup)

If you’re using HTTPS, your remote repo URL looks like https://github.com/YourUsername/YourRepo.git. Common issues here:

  • 2-Factor Authentication (2FA) enabled: You can’t use your regular GitHub password anymore. Instead, generate a Personal Access Token (PAT) to use as your password:
    1. Go to GitHub → Settings → Developer settings → Personal access tokens → Tokens (classic)
    2. Generate a token with the repo permission checked, save it somewhere safe (you won’t see it again!)
    3. When prompted for a password during git push, paste this token instead.
  • Cached wrong credentials: Open Windows Credential Manager (search for it in the Start menu), go to "Windows Credentials", find any entries for github.com, delete them, then try pushing again—you’ll be prompted to enter your credentials (or PAT) fresh.

Option 2: SSH (No More Password Prompts)

For long-term use, SSH is more convenient. Here’s how to set it up:

  1. Generate an SSH key in Git Bash:
ssh-keygen -t ed25519 -C "your-github-email@example.com"

Press Enter through all prompts to accept default settings—this creates id_ed25519 (private key) and id_ed25519.pub (public key) in C:\Users\YourUsername\.ssh.
2. Copy the public key: Open id_ed25519.pub with Notepad, select all, and copy it.
3. Add it to GitHub: Go to GitHub → Settings → SSH and GPG keys → New SSH key. Paste the key, give it a descriptive name, and save.
4. Test the connection:

ssh -T git@github.com

If you see Hi YourUsername! You've successfully authenticated, but GitHub does not provide shell access., you’re good to go.

Check Your Remote Repository Setup

A wrong remote URL is a super common culprit. Run this to list your current remotes:

git remote -v
  • If nothing shows up, add the correct remote:
    # HTTPS
    git remote add origin https://github.com/YourUsername/YourRepo.git
    # OR SSH
    git remote add origin git@github.com:YourUsername/YourRepo.git
    
  • If the URL is wrong, delete the old remote first:
    git remote remove origin
    

Then re-add the correct one as above.

Follow the Exact Push Workflow

Make sure you’re in your project’s root folder, then run these steps in order:

  1. Initialize the repo (if you haven’t already):
git init
  1. Stage all files for commit:
git add .
  1. Commit your changes with a descriptive message:
git commit -m "Initial commit: Add project files"
  1. Push to GitHub (the -u sets origin main as your default upstream branch):
git push -u origin main

Note: GitHub uses main as the default branch now (not master), so double-check you’re using the right branch name.

Fix Common Error Messages
  • fatal: remote origin already exists: You already added a remote—just delete it with git remote remove origin then re-add the correct URL.
  • Permission denied (publickey): Double-check that your SSH public key is correctly added to GitHub, or switch to HTTPS with a PAT.
  • fatal: unable to access 'https://github.com/...': OpenSSL SSL_read: Connection was reset, errno 10054: This is usually a network issue. Try switching to a different network, or if you use a proxy, configure Git to use it:
    git config --global http.proxy http://your-proxy-address:port
    git config --global https.proxy http://your-proxy-address:port
    
    To remove the proxy later:
    git config --global --unset http.proxy
    git config --global --unset https.proxy
    
  • error: failed to push some refs to 'github.com:...': This means the remote repo has content you don’t have locally (like a README you created on GitHub’s web interface). Pull and merge first:
    git pull origin main --allow-unrelated-histories
    
    Then run git push again.

内容的提问来源于stack exchange,提问作者Rehman Maqsood

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:46:09