Push rejected: Push to origin/master was rejected

解决方法:你需要从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

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

猜你喜欢

转载自blog.csdn.net/qq_35193093/article/details/80686505
今日推荐