git push 遇到错误error: failed to push some refs to "xx.git" 解决方案
问题描述
- 在本地有代码,但无git 记录
- 在gitcode 创建一个项目
- 在本地创建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
- 本地与远程挂钩
# 进入目录,打开命令行
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
解决办法:
- 在远程创建一个branch master
- 在本地
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 成功啦!