how to fix: error: failed to push some refs to 博客分类: GIT
程序员文章站
2024-03-13 13:49:09
...
最近在看GIT的相关教程,是廖雪峰老师的教程:http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000
这个教程是从入门开始的,所以也还比较好懂。教程的前半部分都是在本地的操作,一切都是没有什么问题的,但是当要把本地的代码push到远程仓库的时候,就遇到了一个小的问题。因为我是在github上建立了一个learngit的仓库,并且建立的时候,顺便勾选建立readme.md文件,作为仓库的第一个提交。
下面是我的执行过程。
$git remote add origin git@github.com:xfxlch/learngit.git //添加远程主机名
$git push -u origin master //把本地的master分支代码push到远程仓库的master分支上。
这个时候得到了下面的错误。
To git@github.com:xfxlch/learngit.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:xfxlch/learngit.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.
然后我就用去执行了如下的命令:
$git pull origin master
执行完之后,什么都提示都没有,然后我再想去push代码的时候,仍然出现了之前的错误。
我很沮丧,就去Google了,然后找到了http://*.com/questions/24114676/git-error-failed-to-push-some-refs-to
git pull --rebase origin master
git push origin master
完整的是这样的
luchenghaodeMacBook-Air:learngit luchenghao$ git pull --rebase origin master
From github.com:xfxlch/learngit
* branch master -> FETCH_HEAD
First, rewinding head to replay your work on top of it...
Applying: add readme
Applying: udpated
Applying: small change
Applying: understand how stage works
Applying: check git status
Applying: add test.txt
luchenghaodeMacBook-Air:learngit luchenghao$ git push origin master
Counting objects: 18, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (14/14), done.
Writing objects: 100% (18/18), 1.48 KiB | 0 bytes/s, done.
Total 18 (delta 4), reused 0 (delta 0)
remote: Resolving deltas: 100% (4/4), done.
To git@github.com:xfxlch/learngit.git
4587b43..a5dca30 master -> master
他会replay之前的操作,就是相当于把我在本地的commit和在github上的commit做一次 彩排,到底哪个先哪个后,按时间顺序排一下,然后再push的时候,就可以正常提交了。
--EOF--
这个教程是从入门开始的,所以也还比较好懂。教程的前半部分都是在本地的操作,一切都是没有什么问题的,但是当要把本地的代码push到远程仓库的时候,就遇到了一个小的问题。因为我是在github上建立了一个learngit的仓库,并且建立的时候,顺便勾选建立readme.md文件,作为仓库的第一个提交。
下面是我的执行过程。
$git remote add origin git@github.com:xfxlch/learngit.git //添加远程主机名
$git push -u origin master //把本地的master分支代码push到远程仓库的master分支上。
这个时候得到了下面的错误。
引用
To git@github.com:xfxlch/learngit.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:xfxlch/learngit.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.
然后我就用去执行了如下的命令:
$git pull origin master
执行完之后,什么都提示都没有,然后我再想去push代码的时候,仍然出现了之前的错误。
我很沮丧,就去Google了,然后找到了http://*.com/questions/24114676/git-error-failed-to-push-some-refs-to
引用
git pull --rebase origin master
git push origin master
完整的是这样的
引用
luchenghaodeMacBook-Air:learngit luchenghao$ git pull --rebase origin master
From github.com:xfxlch/learngit
* branch master -> FETCH_HEAD
First, rewinding head to replay your work on top of it...
Applying: add readme
Applying: udpated
Applying: small change
Applying: understand how stage works
Applying: check git status
Applying: add test.txt
luchenghaodeMacBook-Air:learngit luchenghao$ git push origin master
Counting objects: 18, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (14/14), done.
Writing objects: 100% (18/18), 1.48 KiB | 0 bytes/s, done.
Total 18 (delta 4), reused 0 (delta 0)
remote: Resolving deltas: 100% (4/4), done.
To git@github.com:xfxlch/learngit.git
4587b43..a5dca30 master -> master
他会replay之前的操作,就是相当于把我在本地的commit和在github上的commit做一次 彩排,到底哪个先哪个后,按时间顺序排一下,然后再push的时候,就可以正常提交了。
--EOF--
推荐阅读
-
how to fix: error: failed to push some refs to 博客分类: GIT
-
how to fix: error: failed to push some refs to 博客分类: GIT
-
git 错误error: failed to push some refs to
-
git push异常整理 error: failed to push some refs to
-
git push origin master 异常 error: failed to push some refs to ‘https://gitee.com/...
-
Git push时报错 ! [remote rejected] master -> master (pre-receive hook declined) error: failed to push some refs to......
-
push时git报错 error: failed to push some refs to 'git@gitee.com:git_zn/jianli.git' 解决办法
-
Git push时报错 ! [remote rejected] master -> master (pre-receive hook declined) error: failed to push some refs to......
-
git使用报错 ! [rejected] master -> master (fetch first) error: failed to push some refs to '略‘
-
push时git报错 error: failed to push some refs to 'git@gitee.com:git_zn/jianli.git' 解决办法