Git的报错的解决方法(详细)
提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
目录
一、Git操作和报错问题解决
1 .创建本地仓库
2. 上传步骤和下载步骤
二、报错解决方案
1.Push rejected (Push was rejected, and update failed with error.)
2.error: src refspec zhangshaohe does not match any
3.! [rejected] master -> master (fetch first)
4.fatal: repository ‘https://xxx@bitbucket.org/xxx.git/’ not found
5.Cant’t Update (No tracked branch configured for branch master or the branch doesn’t exist.)
一、Git操作和报错问题解决
1 .创建本地仓库
git config --global user.name "shaohe-zhang" #配置注册时的用户名git config --global user.email "805414400@qq.com" #配置注册时的邮箱git config --list #检查配置信息mkdir j2eecd j2eegit init#初始化在本地仓库中,创建文件1.txtgit add 1.txt#新增文件到git中处理git commit -m "提示信息"#提交,设置说明信息git remote add origin https://gitee.com/nutony/j2ee.git#远程仓库git push -u origin mas`在这里插入代码片`ter #把本地仓库的资源 提交给Git服务器
2. 上传步骤和下载步骤
上传git add .#.代表上传本文件夹下所有文件git commit -m "提示消息"git push origin master下载git clone https://gitee.com/cgblpx/cgb210801.git #clone后边是git仓库地址
二、报错解决方案
1.Push rejected (Push was rejected, and update failed with error.)
报错代码如下(示例):
Push rejectedPush was rejected, and update failed with error.
解决方法:
切换到自己项目所在的目录,右键选择GIT BASH Here,Idea使用Alt+F12在窗口中输入命令
git pullgit pull origin mastergit pull origin master --allow-unrelated-histories在idea中重新push自己的项目
如何还是不行进行强制上传
git push -u origin master -f
2.error: src refspec zhangshaohe does not match any
报错代码如下(示例):
error: src refspec zhangshaohe does not match anyerror: failed to push some refs to 'https://gitee.com/Ys1550115/the-happy-room.git'
解决方法:
错误原因是,我本地分支是master,我要提交到done分支,因为这是不同的分支,所以要以这种形式提交(mester:done)
git push origin master:done
3.! [rejected] master -> master (fetch first)
报错代码如下(示例):
! [rejected] master -> master (fetch first)error: failed to push some refs to 'https://gitee.com/zhang-shaohe/workspace.git'
解决方法:
方法一 可以通过如下命令进行代码合并
git pull --rebase origin master#合并完之后重启dom窗口,重新运行如下命令进行提交git push origin master
方法二 通过命令强制提交
git push -u origin master -f
4.fatal: repository ‘https://xxx@bitbucket.org/xxx.git/’ not found
报错代码如下(示例):
fatal: repository 'https://xxx@bitbucket.org/xxx.git/' not found
解决方法:
输入下面这行命令设置远程url为修改后的地址
git remote set-url origin https://xxx@xxx/xxx/new_directory.git
改了之后可以查看remote链接,命令如下
git remote -v
5.Cant’t Update (No tracked branch configured for branch master or the branch doesn’t exist.)
报错代码如下(示例):
No tracked branch configured for branch master or the branch doesn't exist.
解决方法:
#在idea的终端里运行如下命令即可git branch --set-upstream-to origin#如果不行尝试如下命令git branch --set-upstream-to origin/maste
发现这个错误的时候可以用git remote -v命令确认一下链接是否正确
不正确就执行替换remote的命令