为什么当我尝试推送到原点时,Git 会告诉我“没有这样远程的‘原点’”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25503017/
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-09 02:22:31  来源:igfitidea点击:

Why does Git tell me "No such remote 'origin'" when I try to push to origin?

gitgithubpushgit-remote

提问by Vijay

I am very new to Git; I only recently created a GitHub account.

我对 Git 很陌生;我最近才创建了一个 GitHub 帐户。

I've just tried to push my very first repository (a sample project), but I'm getting the following error:

我刚刚尝试推送我的第一个存储库(示例项目),但出现以下错误:

No such remote 'origin'

I ran the following commands:

我运行了以下命令:

git init
git commit -m "first commit"
git remote add origin https://github.com/VijayNew/NewExample.git
git push -u origin master

However, when I ran git commit -m "first commit", I got the following message:

但是,当我运行 git commit -m "first commit" 时,我收到以下消息:

nothing added to commit but untracked files present (use "git add" to track)

So then I tried to set origin, using

然后我尝试设置origin,使用

git remote set-url origin https://github.com/VijayNew/NewExample.git

But I got the following error:

但我收到以下错误:

No such remote 'origin'

What did I do wrong, and what should I do?

我做错了什么,我该怎么办?

回答by jub0bs

Two problems:

两个问题:

1 - You never told Git to start tracking any file

1 - 你从来没有告诉 Git 开始跟踪任何文件

You write that you ran

你写你跑了

git init
git commit -m "first commit"

and that, at that stage, you got

在那个阶段,你得到了

nothing added to commit but untracked files present (use "git add" to track).

Git is telling you that you never told it to start tracking any files in the first place, and it has nothing to take a snapshot of. Therefore, Git creates no commit. Before attempting to commit, you should tell Git (for instance):

Git 告诉你,你从一开始就没有告诉它开始跟踪任何文件,而且它没有任何东西可以拍快照。因此,Git 不创建提交。在尝试提交之前,您应该告诉 Git(例如):

Hey Git, you see that README.mdfile idly sitting in my working directory, there? Could you put it under version control for me? I'd like it to go in my first commit/snapshot/revision...

嘿 Git,你看到那个README.md文件闲置在我的工作目录中了吗?你能帮我把它置于版本控制之下吗?我希望它出现在我的第一个提交/快照/修订中...

For that you need to stagethe files of interest, using

为此,您需要暂存感兴趣的文件,使用

git add README.md

beforerunning

跑步

git commit -m "some descriptive message"

2 - You haven't set up the remote repository

2 - 您尚未设置远程存储库

You then ran

然后你跑了

git remote add origin https://github.com/VijayNew/NewExample.git

After that, your local repository should be able to communicate with the remote repository that resides at the specified URL (https://github.com/VijayNew/NewExample.git)... provided that remote repo actually exists! However, it seems that you never created that remote repo on GitHub in the first place: at the time of writing this answer, if I try to visit the correponding URL, I get

之后,您的本地存储库应该能够与位于指定 URL ( https://github.com/VijayNew/NewExample.git)的远程存储库通信...前提是远程存储库确实存在!但是,您似乎从未首先在 GitHub 上创建该远程存储库:在撰写此答案时,如果我尝试访问相应的 URL,我会得到

enter image description here

在此处输入图片说明

Before attempting to push to that remote repository, you need to make sure that the latter actually exists. So go to GitHub and create the remote repo in question. Then and only then will you be able to successfully push with

在尝试推送到该远程存储库之前,您需要确保后者确实存在。因此,转到 GitHub 并创建有问题的远程存储库。只有这样,您才能成功推送

git push -u origin master

回答by Emil Davtyan

I'm guessing you didn't run this command after the commit failed so just actually run this to create the remote :

我猜你在提交失败后没有运行这个命令所以只是实际运行它来创建远程:

 git remote add origin https://github.com/VijayNew/NewExample.git

And the commit failed because you need to git addsome files you want to track.

提交失败,因为您需要git add一些要跟踪的文件。

回答by ishandutta2007

I faced this issue when I was tring to link a locally created repo with a blank repo on github. Initially I was trying git remote set-urlbut I had to do git remote addinstead.

当我试图将本地创建的存储库与 github 上的空白存储库链接时,我遇到了这个问题。最初我正在尝试,git remote set-url但我不得不这样做git remote add

git remote add origin https://github.com/VijayNew/NewExample.git