Gitee本地项目上传及下载教程
1.Gitee仓库创建
①登录Gitee官网,在首页右上角选择加号,点击新建仓库。

②配置仓库
选择【初始化仓库】 ----【设置模板】----【选择分支模型】,其他的默认
注:【.gitignore一项,建议默认不选择状态】容易在本地项目上传时与本地master分支关联失败,导致项目提交报错。

【结果】

2.上传本地项目
(1)安装 【git工具】,找到安装目录双击打开【git-bash.exe】


(2)找到本地项目的路径【D:\vue-cli\projects\vue-mall】
在【git工具】中将路径切换到项目路径
Abelfeng@Abelfeng MINGW64 / $ cd D:vue-cli/projects/vue-mall 
(3)配置【git】连接【gitee账号】
① 获取密钥【qq邮箱即可】,后续的步骤全部回车即可【运行完不要关闭界面,需要找到密钥的保存地址】
Abelfeng@Abelfeng MINGW64 / $ cd D:vue-cli/projects/vue-mall Abelfeng@Abelfeng MINGW64 /d/vue-cli/projects/vue-mall $ ssh-keygen -t RSA -C "[email protected]" Generating public/private RSA key pair. Enter file in which to save the key (/c/Users/Lenovo-pc/.ssh/id_rsa): /c/Users/Lenovo-pc/.ssh/id_rsa already exists. Overwrite (y/n)? y Enter passphrase for "/c/Users/Lenovo-pc/.ssh/id_rsa" (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /c/Users/Lenovo-pc/.ssh/id_rsa Your public key has been saved in /c/Users/Lenovo-pc/.ssh/id_rsa.pub The key fingerprint is: SHA256:tVSPxkq8WxYVT5uZkBfuYNdKH6BiR6U1oKi0esg [email protected] The key's randomart image is: +---[RSA 3072]----+ | .o=+.| | . o+++ .| | o .====.o | | = ++B=o.B | | o =S=+oo B | | . o o . .o = .| | E o . o | | . | | | +----[SHA256]-----+ Abelfeng@Abelfeng MINGW64 /d/vue-cli/projects/vue-mall $ 【$ ssh-keygen -t RSA -C "[email protected]"】

② 成功获取到密钥,到提示存放的位置找到密钥文件并复制密钥文件中的密钥。
【打开文件(可用记事本打开),复制里面的密钥(所有内容)】


③ 将密钥复制到【gitee账号】----【设置】----【SSH公钥】----【公钥】----【添加】

【输入gitee账号密码完成添加】
④ 检验【git】与【gitee】之间是否建立连接,回到【git bash 界面,输入ssh -T [email protected]】。
Abelfeng@Abelfeng MINGW64 /d/vue-cli/projects/vue-mall $ ssh -T [email protected] Hi XFF-T(@账户名)! You've successfully authenticated, but GITEE.COM does not provide shell access. 
(4)配置【git工具】
①配置【git】全局变量
git config --global user.name "gitee账号名" git config --global user.email "gitee绑定的邮箱"
②【检验】
git config --list
(5)初始化仓库
【注:git-bash工具指向的路径 就是 本地新建立的仓库】
git init
(6)实现本地仓库与gitee仓库的连接
【绑定本地仓库与远程仓库】
【点击新建仓库】----【查看代码】----【点击ssh】----【复制ssh旁边的地址】
git remote add origin [远程仓库的地址]

(7)添加上传的指定文件
【添加文件到暂存区】
git add 文件
(8)提交上传文件
git commit -m "提交信息备注"
(9)完成文件上传
git push origin master
【结果】

3.上传问题
报错:fatal: refusing to merge unrelated histories
原因:本地仓库和 Gitee 上的远程仓库,没有任何共同的提交历史(Gitee 认为这是两个完全独立的仓库),因此拒绝执行操作。
针对性解决方案:
方案 1:合并不相关历史(保留本地 + 远程内容) 【适合远程仓库有有用内容(比如 README)、不想丢失的情况】 # 步骤1:先确保本地仓库已关联远程(没关联的话先执行这行,替换为你的Gitee仓库地址) git remote add origin https://gitee.com/你的用户名/仓库名.git # 步骤2:拉取远程代码,并允许合并不相关历史(核心解决参数) # 注意:分支名默认是 main 或 master,确认自己的分支(新手一般是main/master) git pull origin master --allow-unrelated-histories 执行后如果出现「合并冲突」(比如本地和远程都有 README.md): ① 打开冲突文件(文件里会有 <<<<<<< HEAD/=======/>>>>>>> origin/master 标记),保留你需要的内容(删除冲突标记); ② 解决冲突后提交: git add . # 暂存冲突文件 git commit -m "解决合并冲突,合并本地与远程不相关历史" 步骤 3:再次推送文件到 Gitee: git push origin master 方案 2:强制覆盖远程仓库(谨慎用!) 适合远程仓库的内容(比如自动生成的 README)没用,只想把本地文件完全上传覆盖远程的情况 # 强制推送本地代码,覆盖远程仓库的所有历史(会删掉远程的所有内容) git push -f origin master