git将新文件推送到裸露的repo失败:“错误:src refspec master不匹配任何内容”。为什么? [英] git push new file to a bare repo failed: "error: src refspec master does not match any." Why?

查看:249
本文介绍了git将新文件推送到裸露的repo失败:“错误:src refspec master不匹配任何内容”。为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  mkdir〜/ gitremote 
cd〜/ gitremote
git init --bare

我可以看到像

的文件名

  HEAD配置钩子对象
分支描述信息引用

OK,然后在另一个目录中,

  git clone trosky @ localhost:/ Users / trosky / gitremote 
vi自述文件(添加一行)
git add。
git commit -m1st file
git push origin master

然后它给出了一个错误:

  $ git push origin master 
错误:src refspec master不匹配任何。
错误:未能将一些文件推送到'trosy @ localhost:/ Users / trosky / gitremote'

我搜索谷歌,它说这种错误是由于远程回购空文件夹。但远程仓库不是空的,而且我在本地提交的文件也不是空的。为什么这个错误仍然会提示?



如何解决它?感谢。

解决方案

尝试使用以下语法:

  git push -u origin master 

由于您正在推入一个空的repo,您需要 明确推送 master
否则,默认 push.policy simple ,Git会在您的远程仓库中寻找一个名为 master 的分支(并且由于远程裸回购是空的,它还没有 master 分支)



当然,你不会看到任何自述文件远程裸回购,因为它是一个裸回购:没有工作的树。


'git clone / Users / trosky / gitremoe '和'git clone'trosy @ localhost:/ Users / trosky / gitremote'


一个使用的文件协议也是ca lled 本地协议,另一个 ssh协议。你不需要SSH。


I was trying this:

mkdir ~/gitremote
cd ~/gitremote
git init --bare

I can see file names like

HEAD        config      hooks       objects
branches    description info        refs

OK, then in another directory,

git clone trosky@localhost:/Users/trosky/gitremote
vi readme (add one line)
git add .
git commit -m "1st file"
git push origin master

Then it gives an error:

$git push origin master
error: src refspec master does not match any.
error: failed to push some refs to 'trosy@localhost:/Users/trosky/gitremote'

I searched google and it says this kind of error is due to empty folder on remote repo. But the remote repo is not empty, and locally I'm committing a file that's not empty either. Why this error still prompts out?

How to fix it? Thanks.

解决方案

Try with the syntax:

git push -u origin master

Since you are pushing to an empty repo, you need to explicitly push master.
Otherwise, the default push.policy being simple, Git would look for a branch named master in your remote repo (and since your remote bare repo is empty, it has no master branch yet)

Of course, you won't see any readme in your remote bare repo, since it is a bare repo: no working tree.

what's the difference between 'git clone /Users/trosky/gitremoe' and 'git clone 'trosy@localhost:/Users/trosky/gitremote'

One is using the file protocol also called local protocol, the other ssh protocol. You don't need ssh here.

这篇关于git将新文件推送到裸露的repo失败:“错误:src refspec master不匹配任何内容”。为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆