前言
本地项目推送到 GitHub,连续踩两个经典坑:OpenSSL SSL_read: Connection was reset连接重置,以及src refspec main does not match any分支不匹配。整理完整操作流程,同时附上前端项目标准.gitignore 配置,方便后续复用。
环境
Windows + Git Bash
问题 1:git push 报错 OpenSSL SSL_read: Connection was reset, errno 10054
问题原因
访问 GitHub 网络不稳定,Git 需要单独配置参数,调整 SSL 与上传缓冲区。
# 配置Git参数
git config --global http.sslVerify false
# 调大上传缓冲区,防止大文件上传中断
git config --global http.postBuffer 524288000
问题 2:error: src refspec main does not match any
问题原因
Git 本地默认生成分支为master,远端很多教程默认使用main,分支名称不一致导致推送失败。
# 正确推送命令
git push -u origin master
✅ 完整全套提交推送命令
# 1.配置参数
git config --global http.sslVerify false
git config --global http.postBuffer 524288000
# 2.暂存+提交代码(新增/修改代码时执行)
git add .
git commit -m "feat: 项目初始化"
# 3.推送到GitHub远端仓库
git push -u origin master
📄 前端项目标准 .gitignore 配置
新建.gitignore文件,复制下面全部内容,避免依赖包、环境密钥、IDE 缓存提交到远程仓库:
# 依赖包
node_modules/
package-lock.json
pnpm-lock.yaml
yarn.lock
# 编译产物
dist/
build/
out/
*.log
# 环境变量(重要!防止数据库密码、密钥泄露)
.env
.env.local
.env.development
.env.production
# 操作系统文件
.DS_Store
Thumbs.db
# IDE 缓存
.idea/
.vscode/
*.swp
*.swo
# 临时文件
*.tmp
*.bak
⚠️ 重要收尾操作
# 恢复SSL校验
git config --global http.sslVerify true
补充提示
- 如果仍然报 10054 连接重置,切换网络重试,大概率是网络波动。
- 查看本地分支命令:
git branch,确认分支名称后再执行 push。 - 提交代码前务必配置.gitignore,严禁将.env 密钥文件上传到公网仓库。