Git 推送错误:“来源似乎不是 git 存储库”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15437719/
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
Git push error: "origin does not appear to be a git repository"
提问by Al Lelopath
I am following the instructions given hereto create a Git repository. All went well until the last line:
我正在按照此处给出的说明创建 Git 存储库。一切顺利,直到最后一行:
$ git push -u origin master
fatal: 'origin' does not appear to be a git repository
fatal: The remote end hung up unexpectedly
致命:'origin' 似乎不是 git 存储库
致命:远程端意外挂断
I'm using git version 1.7.11.3 on OS X 10.6.8
我在 OS X 10.6.8 上使用 git 版本 1.7.11.3
$ git remote -v
returns nothing
什么都不返回
Config file for the repository:
存储库的配置文件:
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
I've had to open sudoers file using sudo visudo command and add the following to it (under # User privilege specification):
我不得不使用 sudo visudo 命令打开 sudoers 文件并向其中添加以下内容(在#User privilege specification 下):
git ALL=(ALL) ALL.
Now if I do:
现在,如果我这样做:
$ git remote add origin /Volumes/500GB/git-repository/myproject.git
it comes back with no error, but I don't see any code in the repository (it has the aforementioned directories like branches, hooks, ...)
它没有错误地返回,但我在存储库中没有看到任何代码(它具有上述目录,如分支、钩子等)
If I do:
如果我做:
$ 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)
采纳答案by ro ko
As it has already been mentioned in che's answerabout adding the remote part, which I believe you are still missing.
正如在che关于添加远程部分的回答中已经提到的那样,我相信您仍然缺少它。
Regarding your edit for adding remote on your local USB drive. First of all you must have a 'bare repository' if you want your repository to be a shared repository i.e. to be able to push/pull/fetch/merge etc..
关于您在本地 USB 驱动器上添加遥控器的编辑。首先,如果您希望您的存储库成为共享存储库,即能够推送/拉取/获取/合并等,您必须有一个“裸存储库”。
To create a bare/shared repository, go to your desired location. In your case:
要创建裸/共享存储库,请转到您想要的位置。在你的情况下:
$ cd /Volumes/500gb/
$ git init --bare myproject.git
See herefor more info on creating bare repository
有关创建裸存储库的更多信息,请参见此处
Once you have a bare repository set up in your desired location you can now add it to your working copy as a remote.
一旦你在你想要的位置设置了一个裸仓库,你现在可以将它作为远程添加到你的工作副本中。
$ git remote add origin /Volumes/500gb/myproject.git
And now you can push your changes to your repository
现在您可以将更改推送到您的存储库
$ git push origin master
回答by Sunny Jim
Here are the instructions from github:
以下是来自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
Here's what actually worked:
这是实际工作的内容:
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
After cloning, then the push command succeeds by prompting for a username and password
克隆后,push命令成功,提示输入用户名和密码
回答by muyuderek
Most likely the remote repository doesn't exist or you have added the wrong one.
很可能远程存储库不存在或者您添加了错误的存储库。
You have to first remove the origin and re-add it:
您必须首先删除原点并重新添加它:
git remote remove origin
git remote add origin https://github.com/username/repository
回答by che
Your config file does not include any references to "origin" remote. That section looks like this:
您的配置文件不包含对“origin”远程的任何引用。该部分如下所示:
[remote "origin"]
url = [email protected]:repository.git
fetch = +refs/heads/*:refs/remotes/origin/*
You need to add the remote using git remote add
before you can use it.
您需要添加遥控器 usinggit remote add
才能使用它。
回答by Roman
When you createa repository in bitbucket.org, it gives you instructions on how to set up your local directory. Chances are, you just forgot to run the code:
当您在bitbucket.org 中创建存储库时,它会为您提供有关如何设置本地目录的说明。很有可能,您只是忘记运行代码:
git remote add origin https://[email protected]/username/reponame.git
git remote add origin https://[email protected]/username/reponame.git
回答by user3353537
May be you forgot to run "git --bare init
" on the remote?
That was my problem
可能是您忘记git --bare init
在遥控器上运行“ ”了吗?那是我的问题
回答by khd
my case was a little different - unintentionally I have changed owner of git repository (project.git directory in my case), changing owner back to the gituser helped
我的情况有点不同 - 我无意中更改了 git 存储库的所有者(在我的情况下为 project.git 目录),将所有者更改回git用户帮助
回答by Hitesh Roy
If you are on HTTPS do this-
如果您使用 HTTPS,请执行此操作-
git remote add origin URL_TO_YOUR_REPO
回答by Aniket
I'll still share my short answer humbly, knowing that I'm super late to answer this question.
我仍然谦虚地分享我的简短回答,因为我知道我回答这个问题已经很晚了。
Here's, a simple and clean explanation that solved my issue
Also, since I was using the SSH keyI used the following command:
另外,由于我使用的是SSH 密钥,因此我使用了以下命令:
- $ git remote add origin [email protected]:{your-username}/{your-remote-repo-branch}
- $ git remote add origin [email protected]:{your-username}/{your-remote-repo-branch}
for instance it would look like:
例如它看起来像:
- $ git remote add origin [email protected]:aniketrb-github/microservices.git
- $ git remote add origin [email protected]:aniketrb-github/microservices.git
If you are using the HTTPS URL, refer to the answer provided by @sunny-jimabove.
如果您使用的是 HTTPS URL,请参考上面@sunny-jim提供的答案。
Do correct me if I'm wrong. Thanks.
如果我错了,请纠正我。谢谢。
回答by Vasyl Gutnyk
I had this problem cause i had already origin remote defined locally. So just change "origin" into another name:
我有这个问题,因为我已经在本地定义了远程源。所以只需将“ origin”更改为另一个名称:
git remote add originNewhttps://github.com/UAwebM...
git remote add originNew https://github.com/UAwebM...
git push -u originNew
git push -u originNew
or u can remove your local origin. to check your remote name type:
或者您可以删除您的本地来源。检查您的远程名称类型:
git remote
git远程
to remove remote - log in your clone repository and type:
删除远程 - 登录您的克隆存储库并键入:
git remote remove origin(depending on your remote's name)
git remote remove origin(取决于您的遥控器名称)