致命错误- 'origin'似乎不是一个git仓库。

14

我创建了一个远程仓库,然后在本地创建了一个本地仓库:

git init

然后使用git add将我需要的文件添加进去,然后使用git commit -m "something"进行提交。

最后使用git push origin master命令。

我遇到了如下错误:fatal:

'origin' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

我是否需要在某些命令中喜欢远程和本地?如果需要,如果我已经添加并提交了,是否可以开始本地覆盖?

编辑:

显然我应该添加 git remote add origin ssh://git@example.com:1234/myRepo.git 但是我应该用什么替换ssh,以及我应该在哪里找到我应该添加的版本。

出现以下错误:

! [rejected]        master -> master (fetch first)
error: failed to push some refs to 
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

1
可能是设置git远程源的重复问题。 - Liam
8个回答

31
当您运行git clone <repo_url>命令来克隆一个仓库时,Git默认会自动创建名为origin的远程仓库。如果这个仓库是通过git init创建的,则没有默认的远程仓库,也没有名为origin的远程仓库。您需要手动设置它。
git remote add origin <repo_url>
repo_url是现有远程代码仓库的路径,您希望与其交换数据。如果在本地磁盘上,它可以是file:///home/me/foo.git/home/me/foo.git。如果在Github上托管,则可以是https://github.com/me/foo.gitssh://git@github.com/me/foo.git
关于第二个“fetch first”错误,您需要在下一次推送之前运行git pull origin <branch>git pull -r origin <branch>

在进行这个操作时,数据是往哪个方向传输的?我本地已经有了我的数据,不想通过错误的方式覆盖它们! - Dave

8

试试这个

git remote add origin <https://github.com/"username"/"repository".git> 

那么尝试再次尝试

git push -u origin master

5
git remote add origin <url>

那么

git push -u origin master

2
我在进行PR时遇到了相同的错误信息。经过仔细检查,我发现我正在错误的目录上执行Git工作流程。
在我的情况下,我只需倒退一步到正确的目录使用 **cd..** ,然后继续操作就没有出现错误了。

0
当我尝试使用git push origin <branch>命令上传代码时,出现了以下错误:
fatal: 'orgin' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

试一下这个

git remote add origin <https://github.com/"username"/"repository".git>

然后再试一次

git push -u origin master

我参考了这位程序员的代码:Hồ Kim Long Sơn


0

执行以下命令

git remote add origin git@github.com:xxxx/xxxx.git

请不要使用SSH!

0

首先,您需要运行此命令:

git remote add origin https://github.com/"USERNAME"/"REPOSITORY_NAME".git

之后是这样的:

git push -u origin "branch name"

这将会起作用!!!


1
请添加文本来解释您的代码,并说明这两个命令的作用! - SwissCodeMen

-2

这是因为您的配置文件包含主词而不是Heroku Git URL。这可能会在您初始化Git超过一次时发生。

  1. 编辑配置文件

    git config --e

  2. 然后将主词编辑为Heroku URL,例如https://git.heroku.com/project_name.git

  3. 保存并退出!

  4. 然后通过git push heroku master推送更新

希望这可以帮助您!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接