我试图按照迈克尔哈特尔的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 remote set-url origin https://username:PERSONAL_ACCESS_TOKEN@github.com:ppreyer/first_app.git
git push -u origin main

你可以在github上使用以下步骤生成个人访问令牌:

转到设置 点击开发者设置 单击Generate new token 生成您的个人访问令牌并将其粘贴到上面的命令上。:)

其他回答

这工作:

git remote rm origin
git remote add origin git@github.com:username/myapp.git

$ git remote add origin git@gitlab.com:abc/backend/abc.git In this command origin is not part of command it is just name of your remote repository. You can use any name you want. First You can check that what it contains using below command $ git remote -v It will gives you result like this origin git@gitlab.com:abc/backend/abc.git (fetch) origin git@gitlab.com:abc/backend/abc.git (push) origin1 git@gitlab.com:abc/backend/abc.git (fetch) origin1 git@gitlab.com:abc/backend/abc.git (push) if it contains your remote repository path then you can directly push to that without adding origin again If it is not contaning your remote repository path Then you can add new origin with different name and use that to push like $ git remote add origin101 git@gitlab.com:abc/backend/abc.git Or you can rename existing origin name add your origin git remote rename origin destination fire below command again $ git remote -v destination git@gitlab.com:abc/backend/abc.git (fetch) destination git@gitlab.com:abc/backend/abc.git (push) It will change your existing repos name so you can use that origin name Or you can just remove your existing origin and add your origin git remote rm destination

git remote set-url origin https://username:PERSONAL_ACCESS_TOKEN@github.com:ppreyer/first_app.git
git push -u origin main

你可以在github上使用以下步骤生成个人访问令牌:

转到设置 点击开发者设置 单击Generate new token 生成您的个人访问令牌并将其粘贴到上面的命令上。:)

该错误消息表明您的git目录中已经有一个远程服务器。 如果您对那个遥控器感到满意,您就可以推送您的代码。如果没有或者你不能推,就:

git remote remove origin
git remote add origin git@github.com:ppreyer/first_app.git

瞧!

您可以看到配置为通过哪些远程存储库连接

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

然后您应该能够继续您的教程。