Updates were rejected because the remote contains work that you do hint: not have locally. This is u

版权声明:转载请注明出处 https://blog.csdn.net/le_17_4_6/article/details/82501843

今天在学习git时,

$  sudo git push origin master  

报错了:

To https://github.com/xxxxx/xxxx.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/xxxx/xxxxx.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.

解决很简单,

$ sudo git pull origin master  //将本地代码先更新到和github上的一样

warning: no common commits
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 3 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From https://github.com/xxxxx/xxxx
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> origin/master
Merge made by the 'recursive' strategy.
 hello_world.txt | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 hello_world.txt

会自动打开一个GUN 什么的编辑界面,ctrl + x退出就好

$  sudo git push origin master  //将本地代码push到github上

Username for 'https://github.com': xxxx
Password for 'https://[email protected]':
Counting objects: 5, done.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (5/5), 522 bytes | 0 bytes/s, done.
Total 5 (delta 0), reused 0 (delta 0)
To https://github.com/xxxx/xxxx.git
   e8064b2..c2bab39  master -> master

代码已经成功上传到了github上,问题解决了。

猜你喜欢

转载自blog.csdn.net/le_17_4_6/article/details/82501843
今日推荐