git 提交代码报错failed to push some refs to 解决笔记

Administrator@SC-201902081500 MINGW64 /e/gitrepository (master)
$ git push django master
To github.com:zgc137/django.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:zgc137/django.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

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

$ git push -u origin master

但依然没能解决问题

出现错误的主要原因是github中的README.md文件不在本地代码目录中

origin是自己在git上创建的仓库名字,我的创建的名字是django

可以通过如下命令进行代码合并【注:pull=fetch+merge]---取+合并

 

git pull --rebase origin master

注:上传代码到远程库,上传之前最好先Pull一下,再执行命令: git pull origin master

$ git pull --rebase django master
Warning: Permanently added the RSA host key for IP address '52.74.223.119' to the list of known hosts.
From github.com:zgc137/django
 * branch            master     -> FETCH_HEAD
First, rewinding head to replay your work on top of it...
Applying: wrote a readme file
Applying: 天天生鲜项目+练习

即pull成功,

接着执行:git push origin master

$ git push -u django master
Enumerating objects: 115, done.
Counting objects: 100% (115/115), done.
Delta compression using up to 12 threads
Compressing objects: 100% (111/111), done.
Writing objects: 100% (114/114), 1.44 MiB | 782.00 KiB/s, done.
Total 114 (delta 3), reused 0 (delta 0)
remote: Resolving deltas: 100% (3/3), done.
To github.com:zgc137/django.git
   eecd635..07115e0  master -> master
Branch 'master' set up to track remote branch 'master' from 'django'.

 

posted @ 2019-05-11 16:19  点点花飞谢  阅读(938)  评论(0编辑  收藏  举报