【已解决】github中git push origin master出错:error: failed to push some refs to(亲测)

【背景】

折腾:

【记录】将googlecode上面的crifanLib迁移到Github上

期间出错:

git push origin master error failed to push some refs to

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

Administrator@PC-20131018OHXV  /cygdrive/e/dev_root/git/crifanLib

$ git remote add origin https: //github .com /crifan/crifanLib .git

Administrator@PC-20131018OHXV  /cygdrive/e/dev_root/git/crifanLib

$ git remote - v

origin  https: //github .com /crifan/crifanLib .git (fetch)

origin  https: //github .com /crifan/crifanLib .git (push)

Administrator@PC-20131018OHXV  /cygdrive/e/dev_root/git/crifanLib

$ git push origin master

Username  for  'https://github.com' :

Password  for  'https://admin@crifan.com@github.com' :

To https: //github .com /crifan/crifanLib .git

  ! [rejected]        master -> master (non-fast-forward)

error: failed to push some refs to  'https://github.com/crifan/crifanLib.git'

To prevent you from losing  history , non-fast-forward updates were rejected

Merge the remote changes (e.g.  'git pull' ) before pushing again.  See the

'Note about fast-forwards'  section of  'git push --help'  for  details.

出错了。

很明显是:

本地没有update到最新版本的项目(git上有README.md文件没下载下来)

本地直接push所以会出错。

【解决过程】

1.看到提示里面,感觉是本地的代码不是最新的。

所以觉得应该是类似于svn中的,先update一下,再去commit,估计就可以了。

所以先去pull试试:

结果直接pull好像是不对的:

do git pull from local fail

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

Administrator@PC-20131018OHXV  /cygdrive/e/dev_root/git/crifanLib

$ git pull

warning: no common commits

remote: Counting objects: 6,  done .

remote: Total 6 (delta 0), reused 0 (delta 0)

Unpacking objects: 100% (6 /6 ),  done .

From https: //github .com /crifan/crifanLib

  * [new branch]      master     -> origin /master

You asked me to pull without telling me  which  branch you

want to merge with, and  'branch.master.merge'  in

your configuration  file  does not tell me, either. Please

specify  which  branch you want to use on the  command  line and

try again (e.g.  'git pull ' ).

See git-pull(1)  for  details.

If you often merge with the same branch, you may want to

use something like the following  in  your configuration  file :

     [branch  "master" ]

     remote =

     merge =

     [remote  "" ]

     url =

     fetch =

See git-config(1)  for  details.

看来需要先搞懂pull的用法。

2.估计是指定对应的要pull的目标即可。

所以再去试试pull origin:

pull origin still not work

?

1

2

3

4

5

Administrator@PC-20131018OHXV  /cygdrive/e/dev_root/git/crifanLib

$ git pull origin

You asked to pull from the remote  'origin' , but did not specify

a branch. Because this is not the default configured remote

for  your current branch, you must specify a branch on the  command  line.

也还是不对。

有空再继续搞懂原理后再弄。。

3.搜:

error: failed to push some refs to

参考:

github – git error: failed to push some refs to – Stack Overflow

去试试:

try git pull rebase origin master

?

1

2

3

4

5

6

Administrator@PC-20131018OHXV  /cygdrive/e/dev_root/git/crifanLib

$ git pull --rebase origin master

From https: //github .com /crifan/crifanLib

  * branch            master     -> FETCH_HEAD

First, rewinding  head  to replay your work on  top  of it...

Applying: add  local  crifanLib to github

可以看到,此时已经把github上最新的文件下载下来了:

now have downloded readme.md file from github repo

即,那个README.md文件。

4.接着再去:

git push origin master

now do git push origin master ok

?

1

2

3

4

5

6

7

8

9

10

11

Administrator@PC-20131018OHXV  /cygdrive/e/dev_root/git/crifanLib

$ git push origin master

Username  for  'https://github.com' :

Password  for  'https://crifancrifancrifan@github.com' :

Counting objects: 19,  done .

Delta compression using up to 4 threads.

Compressing objects: 100% (14 /14 ),  done .

Writing objects: 100% (18 /18 ), 112.33 KiB,  done .

Total 18 (delta 0), reused 0 (delta 0)

To https: //github .com /crifan/crifanLib .git

    6bae951..32d67c7  master -> master

即可成功把本地的文件都上传到github上面去了。

5.此时再去github网站上也就可以看到对应文件了:

github project can see files

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这个错误提示是因为你的本地分支没有与远程分支建立关联。你可以尝试以下几种方法解决这个问题。 1. 检查本地分支名称:确认你本地分支的名称是否正确。根据引用和引用的错误提示,可以看出分别使用了"main"和"master"作为本地分支名称。确保你使用的是正确的本地分支名称。 2. 拉取远程分支到本地:可以尝试使用git pull命令从远程仓库拉取最新的代码到你的本地分支。根据引用的命令示例,可以使用以下命令来拉取远程分支到本地: ``` git pull origin [远程分支名称]:<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [$ git push -u origin main error: src refspec main does not match any error: failed to pus](https://blog.csdn.net/LJT_SIX/article/details/126933135)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [git push 大坑,错误error: src refspec master does not match any. error: failed to push some refs to](https://blog.csdn.net/qq_43142509/article/details/124182138)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [git push 错误 error: src refspec master does not match anyerror: failed to push some refs to](https://blog.csdn.net/weixin_43810303/article/details/131208606)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值