git push origin master 报错 failed to push some refs to '仓库地址'

我的操作

  • 系统信息:windows 10

  • 鼠标 右键 单击 目标文件夹 (目录 ),出现 Git bash here 菜单。

  • 鼠标 左键 单击 Git bash here 菜单,出现 Git 客户端窗口

  • git init

  • 返回:Initialized empty Git repository in '文件夹绝对路径'

  • git add .(半角英文句号)

  • 无返回

  • git commit -m "学习路线和必备书籍"

  • 返回:

[master (root-commit) 3b5e781] 学习路线和必备书籍
 8 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 "0-Books/1-Java\346\240\270\345\277\203\346\212\200\346\234\257\345\215\2671-10.pdf.pdf"
 create mode 100644 "0-Books/2-Java\346\240\270\345\277\203\346\212\200\346\234\257\345\215\2672-9.pdf"
 create mode 100644 "0-Books/3-Java\347\274\226\347\250\213\346\200\235\346\203\263-4.pdf"
 create mode 100644 "0-Books/4-Effective\302\240Java-2.pdf"
 create mode 100644 "0-Books/5-\346\267\261\345\205\245\347\220\206\350\247\243Java\350\231\232\346\213\237\346\234\272-2.pdf"
 create mode 100644 "0-Books/6-Java8\350\231\232\346\213\237\346\234\272\350\247\204\350\214\203.pdf"
 create mode 100644 "0-Books/7-Java\350\247\243\346\203\221.pdf"
  • git remote add origin https://github.com/pyjack/Java.git # 添加远程分支

  • 无返回信息

  • git push origin master # 进行提交操作
    出现报错


报错信息

To https://github.com/pyjack/Java.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/pyjack/Java.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 创建仓库,自动生成了 README.md相当于在 master 分支进行了一次代码提交操作,但是本地初始化的仓库却没有提交记录,也没有 README.md 文件。

解决办法

参考自 github 报错 failed to push some refs to …

  • 执行 git pull --rebase origin master
  • 返回
From https://github.com/pyjack/Java
 * branch            master     -> FETCH_HEAD
First, rewinding head to replay your work on top of it...

Applying: 学习路线和必备书籍
  • 目标文件夹下出现 README.md 文件

最后执行

git push -u origin master

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值