GitHub学习-----如何解决 error: failed to push some refs to git

来源:互联网 发布:网络咨询和护士哪个好 编辑:程序博客网 时间:2024/06/04 17:41

错误

在使用git 对源代码进行push到gitHub时可能会出错,信息如下:


p-yf-ldf-151:UICollectionViewItemSelectDemo pengjiaxin$ git push origin master

To https://github.com/xinyu1105/UICollectionViewDemo.git

 ! [rejected]        master -> master (fetch first)

error: failed to push some refs to 'https://github.com/xinyu1105/UICollectionViewDemo.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.



解决方法

1>此时很多人会尝试下面的命令把当前分支代码上传到master分支上。

$ git push -u origin master
但依然没能解决问题

2>出现错误的主要原因是github中的README.md文件不在本地代码目录中,可以通过如下命令进行代码合并【注:pull=fetch+merge]

$ git pull --rebase origin master

3>执行上面代码后可以看到本地代码库中多了README.md文件

4>此时再执行下面语句 即可完成代码上传到github

git push -u origin master



阅读全文
0 0
原创粉丝点击