Git 推送错误:“来源似乎不是 git 存储库”

问题描述 投票:0回答:15

我按照此处给出的说明创建 Git 存储库。一切都很顺利,直到最后一行:

$ git push -u origin master

致命:“origin”似乎不是 git 存储库

fatal:远端意外挂断

我在 OS X 10.6.8 上使用 git 版本 1.7.11.3

$ git remote -v

不返回任何内容

存储库的配置文件:

[core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true ignorecase = true

我必须使用 sudo visudo 命令打开 sudoers 文件并向其中添加以下内容(在 # 用户权限规范下):

git ALL=(ALL) ALL.

现在如果我这样做:

$ git remote add origin /Volumes/500GB/git-repository/myproject.git

它返回时没有错误,但我在存储库中没有看到任何代码 (它有前面提到的目录,如分支、钩子……)

如果我这样做:

$ git push -u origin master fatal: 'origin' does not appear to be a git repository fatal: The remote end hung up unexpectedly $ git remote -v origin /Volumes/500GB/git-repository/myproject.git (fetch) origin /Volumes/500GB/git-repository/myproject.git (push)
    
git git-remote
15个回答
90
投票
正如

che的回答中已经提到的关于添加远程部分,我相信您仍然缺少它。

关于在本地 USB 驱动器上添加遥控器的编辑。首先,如果您希望您的存储库成为共享存储库,即能够推送/拉取/获取/合并等,那么您必须有一个“裸存储库”。

要创建裸/共享存储库,请转到您所需的位置。对于你的情况:

$ cd /Volumes/500gb/ $ git init --bare myproject.git

请参阅

此处了解有关创建裸存储库的更多信息

在所需位置设置裸存储库后,您现在可以将其作为远程添加到工作副本中。

$ git remote add origin /Volumes/500gb/myproject.git

现在您可以将更改推送到存储库

$ git push origin master
    

38
投票
以下是来自 github 的说明:

touch README.md git init git add README.md git commit -m "first commit" git remote add origin https://github.com/tqisjim/google-oauth.git git push -u origin master

这是实际有效的:

touch README.md git init git add README.md git commit -m "first commit" git remote add origin https://github.com/tqisjim/google-oauth.git git clone origin master

克隆后,push 命令成功,提示输入用户名和密码


29
投票
很可能远程存储库不存在或者您添加了错误的存储库。

您必须先删除原点并重新添加它:

git remote remove origin git remote add origin https://github.com/username/repository
    

12
投票
您的配置文件不包含任何对“origin”远程的引用。该部分如下所示:

[remote "origin"] url = [email protected]:repository.git fetch = +refs/heads/*:refs/remotes/origin/*

您需要使用

git remote add

添加遥控器才能使用它。


6
投票

5
投票
可能您忘记在遥控器上运行“

git --bare init

”?
这就是我的问题


5
投票
我仍然会谦虚地分享我的简短答案,因为我知道我回答这个问题已经太晚了。

这是一个简单明了的解释,解决了我的问题

另外,由于我使用的是

SSH 密钥,所以我使用了以下命令:

例如它看起来像:

如果您使用的是 HTTPS URL,请参阅上面

@sunny-jim 提供的答案。

如果我错了,请纠正我。谢谢。


3
投票
我的情况有点不同 - 无意中我更改了 git 存储库的所有者(在我的情况下为 project.git 目录),将所有者更改回

git 用户帮助


3
投票
如果您使用的是 HTTPS,请执行此操作 -

git remote add origin URL_TO_YOUR_REPO
    

2
投票
我遇到这个问题是因为我已经在本地定义了 origin 远程。 所以只需将“

origin”更改为另一个名称即可:

git远程添加originNewhttps://github.com/UAwebM...

git Push -u originNew

或者您可以删除您的本地来源。 检查您的远程名称类型:

git远程

要删除远程 - 登录您的克隆存储库并输入:

git远程删除原点(取决于您的远程名称)


2
投票
为了解决这个问题。我只需创建一个新文件夹并放入一些新文件。然后使用这些commond。

* git add . * git commit * git remote add master `your address`

然后它告诉我登录。 输入您的用户名和密码。 之后

git pull git push origin master

完成将代码推送到 github


2
投票
这是我解决这个问题的方法

转到 Github 上的远程存储库并复制项目的存储库 url。

在 git bash 上输入:git remote add origin

远程存储库 url 位于此处


2
投票
设置远程存储库 URL 对我有用:

git remote set-url origin https://github.com/path-to-repo/MyRepo.git


    


1
投票
这就是我们遇到的问题,因为您的存储库无法从 CLI 访问,或者您无权这样做 第二种情况很简单,您只需请求访问权限即可。 对于第一种情况,如果

git push origin <private_branch_name>

 不起作用,那么它将在 CLI 本身中给出解决方案
只需一步即可:

  1. git remote add <name> <URL>
    enter image description here <URL>
    可以使用Gitlab/Github的UI -> 克隆 -> 复制 https 来访问。关联
    然后
  2. git push origin <private_branch name>
    现在提高MR。
    参考图片。

0
投票
如果你是像我这样的傻瓜,请确保你确实输入了“origin”而不是“orgin”:D

© www.soinside.com 2019 - 2024. All rights reserved.