- 在git客户端上传的时候一直报错,显示没法上传到github
- 报错信息以下
$ git push -u origin master
To git@github.com:**/Demo.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to ‘git@github.com:**/Demo.git’
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. ‘git pull’)
hint: before pushing again.
hint: See the ‘Note about fast-forwards’ in ‘git push –help’ for details.
- 解决方法(问度娘的,由于本身是刚搭建的,因此选择了第一种,强制push,如果你已经搭建好的博客,仍是选择其余几种方法——>第一种最省事,最快)
- 缘由:远程repository和我本地的repository冲突致使的,而在建立版本库后,在github的版本库页面点击了建立README.md文件的按钮建立了说明文档,可是却没有pull到本地。这样就产生了版本冲突的问题。
- 方法以下几种:
- 使用强制push的方法:
$ git push -u origin master -f
- 这样会使远程修改丢失,通常是不可取的,尤为是多人协做开发的时候。
- push前先将远程repository修改pull下来
$ git pull origin master
$ git push -u origin master
- 若不想merge远程和本地修改,能够先建立新的分支:
$ git branch [name]
$ git push -u origin [name]