git push origin 给出 refspec 的远程部分不是有效名称

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11945289/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 14:23:33  来源:igfitidea点击:

git push origin gives remote part of refspec is not a valid name

git

提问by darKoram

I have created a remote repo using my GitHub account at https://github.com/darKoram/sphero_tracker.git. So far it just contains some wiki pages, but I'm ready to upload my code.

我在https://github.com/darKoram/sphero_tracker.git使用我的 GitHub 帐户创建了一个远程存储库 。到目前为止,它只包含一些 wiki 页面,但我已准备好上传我的代码。

I use

我用

git push origin [email protected]:/darkoram/shpero_tracker.git

I also tried

我也试过

git push origin https://github.com/darKoram/sphero_tracker.git

both times I get

两次我都得到

remote part of refspec is not a valid name in https://github.com/darKoram/sphero_tracker.git

refspec 的远程部分在https://github.com/darKoram/sphero_tracker.git 中不是有效名称

I've pushed before without problems. Just don't know what I'm doing wrong here.

我之前推过没有问题。只是不知道我在这里做错了什么。



I got a little further. Followed the instructions by marshall and the generating-ssh-keys link below, but still get

我走得更远了一点。按照 marshall 的说明和下面的生成 ssh-keys 链接,但仍然得到

git push -u origin master ERROR: Repository not found. fatal: The remote end hung up unexpectedly

git push -u origin master 错误:未找到存储库。致命:远端意外挂断

I've established that my ssh keys are good and verified that they exist on github by tring to add what's in my id_rsa.pub to my github (it said the key already existed).

我已经确定我的 ssh 密钥是好的,并且通过 tring 将我的 id_rsa.pub 中的内容添加到我的 github(它说密钥已经存在)来验证它们存在于 github 上。

$ ssh -T [email protected] Hi darKoram! You've successfully authenticated, but GitHub does not provide shell access.

$ ssh -T [email protected] 嗨 darKoram!您已成功通过身份验证,但 GitHub 不提供 shell 访问。

https://help.github.com/articles/generating-ssh-keys

https://help.github.com/articles/generating-ssh-keys

ssh -T -p 443 [email protected] The authenticity of host '[ssh.github.com]:443 ([207.97.227.248]:443)' can't be established. RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '[ssh.github.com]:443,[207.97.227.248]:443' (RSA) to the list of known hosts. Hi darKoram! You've successfully authenticated, but GitHub does not provide shell access

ssh -T -p 443 [email protected] 无法确定主机'[ssh.github.com]:443 ([207.97.227.248]:443)' 的真实性。RSA 密钥指纹为 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48。您确定要继续连接吗(是/否)?是 警告:将 '[ssh.github.com]:443,[207.97.227.248]:443' (RSA) 永久添加到已知主机列表中。嗨 darKoram!您已成功通过身份验证,但 GitHub 不提供 shell 访问

git remote -v origin [email protected]:darKoram/shpero_tracker.git (fetch) origin [email protected]:darKoram/shpero_tracker.git (push)

git remote -v origin [email protected]:darKoram/shpero_tracker.git (fetch) origin [email protected]:darKoram/shpero_tracker.git (push)

but the repo certainly seems to exist http://www.pasteall.org/pic/show.php?id=36560

但回购肯定似乎存在 http://www.pasteall.org/pic/show.php?id=36560

回答by Andrew Marshall

Why not follow the instructions GitHub gives you?

为什么不按照GitHub 给您说明进行操作

git remote add origin [email protected]:darkoram/shpero_tracker.git
git push -u origin master

The commands you're issuing are saying "push to the remote repo named originthe branch named [email protected]:/darkoram/shpero_tracker.git", which is obviously not correct.

您发出的命令是说“推送到名为名为origin分支的远程存储库[email protected]:/darkoram/shpero_tracker.git”,这显然是不正确的。

回答by Andrew Marshall

The original poster's original question says:

原始海报的原始问题说:

I use

git push origin [email protected]:/darkoram/shpero_tracker.git

I also tried

git push origin https://github.com/darKoram/sphero_tracker.git

both times I get

remote part of refspec is not a valid name in https://github.com/darKoram/sphero_tracker.git

我用

git push origin [email protected]:/darkoram/shpero_tracker.git

我也试过

git push origin https://github.com/darKoram/sphero_tracker.git

两次我都得到

refspec 的远程部分在https://github.com/darKoram/sphero_tracker.git 中不是有效名称

The error refers to the fact that you're not using a valid refspec. A refspec takes the following form (items in []are optional, and items in <>are parameters):

该错误是指您没有使用有效的 refspec。refspec 采用以下形式(输入项[]是可选的,输入项<>是参数):

[+]<source>[:<destination>]

In the format above, both the source and the destination are references, and branches in Git are references, so you can use branches as refspecs. For example, the following are both valid and equivalent refspecs:

在上面的格式中,源和目标都是引用,而 Git 中的分支是引用,因此您可以将分支用作 refspecs。例如,以下既是有效的又是等效的 refspecs:

master
master:master

Using the two refspecs with git push:

使用两个 refspecs git push

git push origin master
git push origin master:master

will both push the local branch masterto the branch named masteron the remote origin.

将本地分支推master送到master远程命名的分支origin

Your Problem

你的问题

You used

你用过

git push origin [email protected]:/darkoram/shpero_tracker.git

[email protected]:/darkoram/shpero_tracker.gitis not a vaid reference/branch, it's the URL for your remote repo. That's probably why Git is complaining that the refspec is not valid.

[email protected]:/darkoram/shpero_tracker.git不是无效的参考/分支,它是您的远程存储库的 URL。这可能就是 Git 抱怨 refspec 无效的原因。

The correct way to push a branch would be

推送分支的正确方法是

git push origin <branch>

See Also

也可以看看

回答by ARK

I use

git push origin [email protected]:/darkoram/shpero_tracker.git

I also tried

git push origin https://github.com/darKoram/sphero_tracker.git

both times I get

remote part of refspec is not a valid name in >https://github.com/darKoram/sphero_tracker.git

我用

git push origin [email protected]:/darkoram/shpero_tracker.git

我也试过

git push origin https://github.com/darKoram/sphero_tracker.git

两次我都得到

refspec 的远程部分在 > https://github.com/darKoram/sphero_tracker.git 中不是有效名称

The solution is to put the branch name at the end of the git command:

解决办法是将分支名称放在git命令的末尾:

git push https://github.com/darKoram/sphero_tracker.git master

回答by VonC

Please consider the case(uppercase, lowercase) you are using for those remote addresses:

请考虑您用于这些远程地址的大小写(大写、小写):

git remote add origin [email protected]:darKoram/shpero_tracker.git
# NOT:
git remote add origin [email protected]:darkoram/shpero_tracker.git # won't work
#                                      ^^^
#                                       |

See:

看:

回答by darKoram

In the end, i was able to connect, but when trying git push origin master i was getting "fast forward" errors despite the fact that my repo was created with only the default Readme.md. I tried the suggestions in the man pages, but in the end, when my dev folders were pushed to github the folder showed up as green and could not be opened. The git pull --rebase I did also somehow excluded my dev files from my local git repo and i've found no way to add them back.

最后,我能够连接,但是在尝试 git push origin master 时,尽管我的存储库仅使用默认的 Readme.md 创建,但我还是收到了“快进”错误。我尝试了手册页中的建议,但最后,当我的 dev 文件夹被推送到 github 时,该文件夹显示为绿色并且无法打开。我所做的 git pull --rebase 也以某种方式从我的本地 git repo 中排除了我的开发文件,我发现无法将它们添加回来。

In the end, i had to create a new github repo and a new local repo. The key in the process is step 3 which pulls the nearly empty (except for Readme.md) repo before attempting to push to it.

最后,我不得不创建一个新的 github 存储库和一个新的本地存储库。该过程中的关键是第 3 步,它在尝试推送之前拉取几乎空的(Readme.md 除外)存储库。

  1. create github repo
  2. git add remote origin (https://... the url in the window on github page)
  3. git clone origin master
  4. create local repo; add; commit;
  5. git push origin
  1. 创建 github 仓库
  2. git add remote origin (https://... github页面窗口中的url)
  3. git clone 原点大师
  4. 创建本地仓库;添加; 犯罪;
  5. git push 原点

I suppose if i didn't accept the dialog box offer to create Readme for repo that 3 would be un-necessary, but it's strange to me that this default option derails the simple repo creation process as elaborated in so many tutorials on the subject.

我想如果我不接受为 repo 创建自述文件的对话框提议,那么 3 将是不必要的,但令我感到奇怪的是,这个默认选项破坏了许多关于该主题的教程中阐述的简单的 repo 创建过程。

回答by Sajjjan Kumar

In my case I am also getting the same error.

就我而言,我也遇到了同样的错误。

fatal: remote part of refspec is not a valid name in https://github.com/username/repo.git

致命:refspec 的远程部分在https://github.com/username/repo.git 中不是有效名称

Firstly I thought it is due to changing the username( as I recently change my username on github) but that's not a problem.

首先,我认为这是由于更改了用户名(因为我最近在 github 上更改了我的用户名),但这不是问题。

When I tried git fetch and then git pullbut getting the same error.

当我尝试git fetch 然后 git pull但得到相同的错误时。

At Last this is just solved by

最后这只是解决了

git push origin master 

No Idea but this worked.

没有想法,但这有效。

回答by szeitlin

I had a similar problem today. FWIW, this fixed it:

我今天遇到了类似的问题。FWIW,这修复了它:

git fetchfollowed by git pull origin mybranch(response: "Already up-to-date")

git fetch其次是git pull origin mybranch(响应:“已经是最新的”)

then git push origin mybranch.

然后git push origin mybranch

I suspect maybe something related to the upstream parent branch needed to be fetched (?). If someone else can explain why this fixed it, I'm all ears.

我怀疑可能需要获取与上游父分支相关的内容(?)。如果其他人可以解释为什么要解决这个问题,我全神贯注。