我试图按照迈克尔哈特尔的Rails教程,但我遇到了一个错误。
我在GitHub注册了,发放了一个新的SSH密钥,并创建了一个新的存储库。但是当我在终端中输入下一行时,我得到了以下错误:
Parkers-MacBook-Pro:.ssh ppreyer$ git remote add origin git@github.com:ppreyer/first_app.git
fatal: remote origin already exists.
只是想知道是否有人遇到过这个问题?
我试图按照迈克尔哈特尔的Rails教程,但我遇到了一个错误。
我在GitHub注册了,发放了一个新的SSH密钥,并创建了一个新的存储库。但是当我在终端中输入下一行时,我得到了以下错误:
Parkers-MacBook-Pro:.ssh ppreyer$ git remote add origin git@github.com:ppreyer/first_app.git
fatal: remote origin already exists.
只是想知道是否有人遇到过这个问题?
当前回答
在特殊情况下,您正在从用作模板的旧存储库开始创建新的存储库(如果不是您的情况,请不要这样做)。完全擦除旧存储库的git文件,这样你就可以开始一个新的存储库:
rm -rf .git
然后像往常一样重新启动一个新的git存储库:
git init
git add whatever.wvr ("git add --all" if you want to add all files)
git commit -m "first commit"
git remote add origin git@github.com:ppreyer/first_app.git
git push -u origin master
其他回答
试试这个命令,对我有用。
Rm -rf .git/
对于那些遇到非常常见的错误“fatal: remote origin already exists.”,或者当试图删除origin时得到“error: could not remove config section remote.”原点”,你需要做的就是手动设置原点。
Windows的POSH~Git for Windows PowerShell(和GitHub for Windows的应用程序)在这方面有一个问题。
就像我经常遇到的那样,我又一次在布置我的章鱼女时遇到了这种情况。这就是我如何让它工作的。
首先,检查你的遥控器:
C:\gd\code\octopress [source +2 ~3 -0 !]> git remote -v
octopress https://github.com/imathis/octopress.git (fetch)
octopress https://github.com/imathis/octopress.git (push)
origin
您首先会注意到我的原点没有url。任何删除它、重命名它的尝试都失败了。
因此,手动更改url:
git remote set-url --add origin https://github.com/eduncan911/eduncan911.github.io.git
然后你可以再次运行git remote -v来确认它是有效的:
C:\gd\code\octopress [source +2 ~3 -0 !]> git remote -v
octopress https://github.com/imathis/octopress.git (fetch)
octopress https://github.com/imathis/octopress.git (push)
origin https://github.com/eduncan911/eduncan911.github.io.git (fetch)
origin https://github.com/eduncan911/eduncan911.github.io.git (push)
这已经修复了数十个我遇到的问题,GitHub, BitBucket GitLab等。
如果你已经为另一个存储添加了项目,比如你上传到github,然后你上传到bitbucket,然后它会显示这种类型的错误。
如何删除错误:删除git-hub文件,然后重复以下步骤…
git init
git remote add origin git@bitbucket.org:Yourname/firstdemotry.git
git add -A
git commit -m 'Message'
git push -u origin master
您可以看到配置为通过哪些远程存储库连接
git remote -v
将返回如下格式的列表:
origin git@github.com:github/git-reference.git (fetch)
origin git@github.com:github/git-reference.git (push)
这可能会帮助你弄清楚最初的“原点”指的是什么。
如果你想保留你用-v看到的远程连接,但仍然想遵循Rails教程,而不必记住'github'(或其他一些名称)用于教程的repo,你可以使用命令重命名你的其他存储库:
git remote rename [current name] [new name]
如:
git remote rename origin oldrepo
然后您应该能够继续您的教程。
该错误消息表明您的git目录中已经有一个远程服务器。 如果您对那个遥控器感到满意,您就可以推送您的代码。如果没有或者你不能推,就:
git remote remove origin
git remote add origin git@github.com:ppreyer/first_app.git
瞧!