
一、准备工作在 Gitee 上创建空仓库登录 Gitee点击右上角 → 新建仓库填写仓库名称建议与本地项目名一致不要勾选 “初始化仓库”README、.gitignore 等保持空仓库复制仓库地址例如https://gitee.com/qinqinshen666/testdincikf.git关联邮箱第一步查看当前 Git 邮箱bashgit config user.email第二步登录 Gitee 公开邮箱打开 gitee.com 登录右上角头像 → 设置 → 邮箱管理找到和你 git config user.email 一致的邮箱点击 设为公开或取消隐私保护https://gitee.com/static/images/logo-black.svg设置路径个人设置 → 邮箱管理 → 找到对应邮箱 → 公开二、初始化并关联远程仓库步骤 1进入项目目录并初始化 Gitbash进入你的项目文件夹cd “c:\Users\sqq\Desktop*”初始化 Git 仓库如果已经是 git 仓库则跳过git init步骤 2添加远程仓库地址⚠️ 重要如果之前已经添加过 origin需要先删除或修改否则会报错 fatal: remote origin already exists.方式 A首次添加仓库从未关联过远程bashgit remote add origin https://gitee.com/*.git方式 B已存在 origin需要修改地址推荐bash先查看当前远程地址git remote -v修改远程地址推荐方式不会丢失历史记录git remote set-url origin https://gitee.com/*…git方式 C删除后重新添加bash删除已有的 origingit remote rm origin重新添加git remote add origin https://.git步骤 3验证远程地址bashgit remote -v输出应显示plainorigin https://gitee.com/.git (fetch)origin https://gitee.com/*.git (push)三、提交并推送代码步骤 4添加文件到暂存区bash添加所有文件git add .步骤 5提交到本地仓库bashgit commit -m “初始提交上传项目到 Gitee”步骤 6拉取远程代码避免冲突如果远程仓库是空的可以跳过此步。如果有内容如 README需要先拉取合并。bash拉取远程 master 分支首次可能需要指定分支git pull origin master --allow-unrelated-histories–allow-unrelated-histories允许合并没有共同历史的分支首次推送时需要步骤 7推送到远程仓库bash推送到 origin 的 master 分支并建立追踪关系git push -u origin master-u或 --set-upstream建立本地分支与远程分支的追踪关系下次可直接用 git push / git pull四、PowerShell 一键脚本Windows如果你需要频繁操作可以将以下命令保存为 PowerShell 脚本powershell设置项目路径Set-Location “c:\Users*.”检查并设置远程仓库地址if (git remote get-url origin 2$null) {git remote set-url origin “https://…gitWrite-Host “✅ 已更新远程仓库地址” -ForegroundColor Green} else {git remote add origin https://gitee.com/…git”Write-Host “✅ 已添加远程仓库地址” -ForegroundColor Green}验证远程地址Write-Host “n 当前远程仓库” -ForegroundColor Cyangit remote -v查看状态Write-Host “n 仓库状态” -ForegroundColor Cyangit status查看分支Write-Host “n 分支信息” -ForegroundColor Cyangit branch -a五、常见问题排查表格问题 原因 解决方案fatal: remote origin already exists 已存在 origin 远程 使用 git remote set-url origin 新地址 或先 git remote rm originfailed to push some refs to 远程有本地没有的提交 先执行 git pull origin master 再 pushCould not resolve host 网络或地址错误 检查 URL 拼写确认网络连接Permission denied 无权限 检查 Gitee 仓库是否私有确认账号密码或 SSH 密钥配置The requested URL returned error: 403 认证失败 检查用户名密码或配置 SSH 密钥六、查看远程分支和日志bash获取远程最新信息git fetch origin查看本地 v2 分支最近3条提交git log --oneline -3 v2查看远程 v2 分支最近3条提交git log --oneline -3 origin/v2已有 Git 仓库只想重新上传代码如果你之前已经 git init 过但历史混乱想清空历史重新上传纯净代码powershell进入项目目录cd “c:\Users\sqq\Desktop\pangcepp\TCSTV1”删除旧的 git 历史保留代码文件Remove-Item -Recurse -Force .git重新初始化git initgit remote add origin https://gitee.com/qinqinshen666/testdincikf.git重新推送bashgit push origin main添加代码配合 .gitignoregit add .git commit -m “上传项目代码”git push -u origin master --force–force 会覆盖远程仓库所有内容谨慎使用