【git】git push 遇到错误error: failed to push some refs to “xx.git“ 解决方案

问题描述

  1. 在本地有代码,但无git 记录
  2. 在gitcode 创建一个项目
  3. 在本地创建ssh 添加公钥到 gitcode
# 创建指定文件名的ssh
ssh-keygen -t rsa -C "youremail@example.com" -f ~/.ssh/id_rsa_gitcode
# 若报错文件不存在,需要检查.ssh是否存在
mkdir c:Users\xx\.ssh
# 查看公钥
cat  ~/.ssh/id_rsa_gitcode.pub
# 将公钥添加到gitcode

在这里插入图片描述

  1. 本地与远程挂钩
# 进入目录,打开命令行
git config --global user.name "your name"
git config --global user.email "your email"
cd existing_folder
git init
git remote add origin xx.git
git add .
git commit -m "Initial commit"
git push -u origin master

问题1 :push时报错 error: failed to push some refs to 'https://gitcode.net/anniaxie/pythonproject.git

原因:远程没有master
解决办法:

  1. 在远程创建一个branch master
  2. 在本地 git pull origin master
    产生第2个问题

问题2:pull 时 报错fatal: ‘remote’ does not appear to be a git repository fatal: Could not read from remote repository.

原因:本地与远程未关联
解决办法:
git branch --set-upstream-to=origin/master master

问题3: pull 时报错fatal: refusing to merge unrelated histories

原因:本地和远程合并冲突
解决办法:

git pull origin master --allow-unrelated-histories

再次 push 成功啦!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值