github commit 报错:error: failed to push some refs to 'https:'错误解决方法

今天在Xcode push代码上去github的时候提示错误,但commit已经成功,根据提示是

the remote contains work that you do not have locally. 

错误原因应该是我在github上之前有修改,但是我没有clone到本地的仓库,这时我又需要commit,则两者发生冲突,英文翻译为检查到本地并没有检测到以前的版本,所以,参照以下网站,即可解决问题:

参考网址:http://stackoverflow.com/questions/20939648/issue-pushing-new-code-in-github


问题描述

I created a new repository on Github which has only Readme.md file now.

I have a newly created RoR project which I wanted to push to this repository. Following are the commands I gave in my Terminal to execute this along with the error I am getting.

git remote add origin https://github.com/aniruddhabarapatre/learn-rails.git

After which I entered my username and password

git push -u origin master

Error ---

To https://github.com/aniruddhabarapatre/learn-rails.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/aniruddhabarapatre/learn-rails.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 merge the remote changes (e.g.,
hint: 'git pull') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

This is my first time pushing my code to a Github repository and I'm lost with the errors. I searched few other questions that are asked here, but none of them had issues first time.


解决办法:

When you created your repository on GitHub, you created a README.md, which is a new commit.

Your local repository doesn't know about this commit yet. Hence:

Updates were rejected because the remote contains work that you do not have locally.

You may want to find to follow this advice:

You may want to first merge the remote changes (e.g., 'git pull') before pushing again.

That is:

git pull
# Fix any merge conflicts, if you have a `README.md` locally
git push -u origin master



你可能感兴趣的:(学习笔记)