上传本地代码到远程仓库 , updates were rejected because the remote contains work .. refusing to merge unrelated.

一 , 自己在码云新建一个仓库

上传本地代码到远程仓库 , updates were rejected because the remote contains work .. refusing to merge unrelated.

二 , 点击创建之后 , 点一下初始化readme文件

上传本地代码到远程仓库 , updates were rejected because the remote contains work .. refusing to merge unrelated.

三 , 仓库默认只有master一个分支,里面有刚才初始化的两个文件,点击分支 1可以看到详情

上传本地代码到远程仓库 , updates were rejected because the remote contains work .. refusing to merge unrelated.

上传本地代码到远程仓库 , updates were rejected because the remote contains work .. refusing to merge unrelated.

四 , 回到桌面新建一个文件夹 , 里面新建一个a.txt (不能是空文件夹 , 会报错)

上传本地代码到远程仓库 , updates were rejected because the remote contains work .. refusing to merge unrelated.

打开文件夹 , 右键点 git bash here

git init (初始化仓库)

git add . (添加本次所有改动到本地暂存区)

git commit -m "本次提交代码描述"  (将暂存区里的改动提交到本地仓库)

git remote add origin 远程仓库地址  (添加远程仓库)
git push -u origin master        ( 远程仓库已有master分支, 但还没跟本地关联)

上传本地代码到远程仓库 , updates were rejected because the remote contains work .. refusing to merge unrelated.

 一顿操作下来居然报错了 , 读一下黄色文字第一行和第二行 , 翻译 : 更新被拒绝因为远程仓库有一些文件你本地没有 

是的 , 远程仓库master分支上是有两个初始化文本的 , 我本地没有

上传本地代码到远程仓库 , updates were rejected because the remote contains work .. refusing to merge unrelated.

所以在git push 本地仓库之前 , 要先git pull远程仓库的最新代码到本地 , 再git push, 一定要记得!! 后面每次提交代码之前也是要先git pull , 再git push

git pull origin 远程分支名 (将远程分支 拉到 本地当前分支)

上传本地代码到远程仓库 , updates were rejected because the remote contains work .. refusing to merge unrelated.

又报错了 ? 读一下最后一行 :  拒绝合并不相关的历史 

意思是现在本地仓库和远程仓库是两个独立没关系的仓库 , 不能直接 pull到本地 , 后面加一个--allow-unrelated-histories 就可以了 

上传本地代码到远程仓库 , updates were rejected because the remote contains work .. refusing to merge unrelated.

按完回车会出现这个页面, 不用管 , 直接关掉cmd , 因为这时候远程仓库那两个文件已经拉到本地了

上传本地代码到远程仓库 , updates were rejected because the remote contains work .. refusing to merge unrelated.

git remote -v (查看远程仓库地址) 

上传本地代码到远程仓库 , updates were rejected because the remote contains work .. refusing to merge unrelated.

最后 , git push , 刷新远程仓库 ,  提交成功

 上传本地代码到远程仓库 , updates were rejected because the remote contains work .. refusing to merge unrelated.

上一篇:【自我总结】文献调研的思路及方法


下一篇:设置右键菜单