GitEE常见问题
前言:本文转载,非原创,如有冒犯,请私聊
一、GitHub提交的时显示Updates were rejected because the remote contains work that you do
每次建立新的仓库,提交的时总会出现这样的错误。Updates were rejected because the remote contains work that you do
错误的git 提交的步骤:
- git init //初始化仓库
- git add .(文件name) //添加文件到本地仓库
- git commit -m “first
- commit” //添加文件描述信息
- git remote add origin + 远程仓库地址 //链接远程仓库,创建主分支 git
- push -u origin master //把本地仓库的文件推送到远程仓库
这样就显示这样的问题了,如下图。
经过查资料发现是因为我们在本地新建库后,与远程仓库的内容不一致导致的。为此在我向远程库推送的时候,要先进行pull,让本地新建的库和远程库进行同步。
正确步骤:
git init //初始化仓库
git add .(文件name) //添加文件到本地仓库
git commit -m “first commit” //添加文件描述信息
git remote add origin + 远程仓库地址 //链接远程仓库,创建主分支
git pull origin master // 把本地仓库的变化连接到远程仓库主分支
git push -u origin master //把本地仓库的文件推送到远程仓库
原文链接:https://blog.csdn.net/aiming66/article/details/81051428
二、Updates were rejected because the tip of your current branch is behind
git提交冲突问题:
Updates were rejected because the tip of your current branch is behind
方案:
这时需要用git pull origin master --allow-unrelated-histories指令
-
按”i”进入输入模式
-
然后 esc键,直接输入”:wq”你会发现这个出现在终端的最下面
-
最后 enter。
注:如果输入指令成功执行,没有报错,可以不用1 2 3 步,正常步骤提交即可。
三、fatal:‘origin’ does not appear to be a git repository fatal:Could not read from remote repository
今天gitlab中遇到的问题:
当 git push origin branch_name时遇到报错如下:
fatal:‘origin’ does not appear to be a git repository
fatal:Could not read from remote repository
原因:
本地分支和远程分支断开连接
解决方法:
cd 本地分支里
1、git branch
——*master 只显示master
然后查看是否从上游拉了
2、git remote –v
——若什么都没有,则和上游已断联系,拉不了代码也推不了代码
加关联
3、git remote add origin ssh://git@gitlab*********************************.git(地址)
然后
4、git fetch origin
——会显示下拉的branch情况
格式为From ssh://gitlab.********************************
* [new branch] XXXXX ->origin/XXXXX
再次检查远程仓库,显示对应的clone地址
git remote –v
——origin git://github.com/schacon/ticgit.git (fetch)
origin git://github.com/schacon/ticgit.git (push)
然后再查分支
git branch –a
——* mater
remotes/origin/XXXXXX **********
具体的切换分支可参考https://blog.csdn.net/tanningzhong/article/details/79724488
git 重命名仓库、修改远程仓库地址、修改仓库配置可参考:https://blog.csdn.net/u011884440/article/details/71246572
原文链接:https://blog.csdn.net/qq_44701258/article/details/99087161