解决git push错误:failed to push some refs to git

解决git push错误:failed to push some refs to git

 

 

一、错误信息

XXXXX MINGW64 /e/gitProjects/myDemoPro (master)
$ git push origin master
To git@github.com:XXXXX/myDemoPro.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'git@github.com:zuiwangzuo/myDemoPro.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
 

二、问题分析

先到github上看看远程repository下到底有啥东西,发现目标库是空的。

但是有一个README.md文件(本地代码中没有),而出现错误的原因是github中的README.md文件不在本地代码目录中。

也就是说我们需要先将远程代码库中的任何文件先pull到本地代码库中,才能push新的代码到github代码库中。

 

三、解决问题

1. 将远程代码库中的代码pull到本地代码库,并且执行合并merge

$ git pull --rebase origin master
warning: no common commits
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 3 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From github.com:zuiwangzuo/myDemoPro
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> origin/master
First, rewinding head to replay your work on top of it...
Applying: 提交初始代码。

2. 再次push代码:

$ git push origin master
Counting objects: 20, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (12/12), done.
Writing objects: 100% (20/20), 2.51 KiB | 0 bytes/s, done.
Total 20 (delta 0), reused 0 (delta 0)
To git@github.com:zuiwangzuo/myDemoPro.git
   8227f7c..aff8663  master -> master


我们看到本地代码已经成功的提交到远程代码中,至此问题解决。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值