git+idea出错 | Push rejected: Push to origin/master was rejected

背景:我是在学习android的时候,遇到的这个问题,我在androidstudio写完代码,运行完demo后,利用git进行commit and push 的时候出现的这个错误 
解决方法:你需要从VCS中的git中pull一下你github中初始化的空仓库,但是你执行VCS->Git->pull也是会报错的,错误如下:

Git Pull Failed: fatal: refusing to merge unrelated histories
  • 1

意思是git拒绝合并两个不相干的东西 
此时你需要在打开Git Bash,然后进入相应的目录,然后敲git命令:

$ git pull origin master --allow-unrelated-histories
  • 1
  • 2

出现类似于这种信息就说明pull成功了:

From https://github.com/danishlyy/HappyBirthday
 * branch            master     -> FETCH_HEAD
Merge made by the 'recursive' strategy.
 README.md | 2 ++
 1 file changed, 2 insertions(+)
 create mode 100644 README.md
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

然后你可以利用git status查看一下当前仓库的状态,是不是所有的全部add并且commit,如果全部完成,那么此时你就可以将本地仓库中的推送到github中,使用如下的git命令:

$ git push -u origin master
  • 1
  • 2

完了,去刷新github,就可以看到东西已经推送成功 
注意: 
可能你在推送的过程中会遇到问题

fatal: AggregateException encountered.
   ▒▒▒▒һ▒▒▒▒▒▒▒▒▒▒
Username for 'https://github.com':
remote: Anonymous access to danishlyy/HappyBirthday.git denied.
fatal: Authentication failed for 'https://github.com/danishlyy/HappyBirthday.git/'
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

原因是因为你的配置文件没有用户名和密码的配置,所以你需要重新输入一下,如果你觉得麻烦,可以直接在配置文件中进行配置。

本文来源: http://blog.csdn.net/u012934325/article/details/71023241
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值