我试图按照迈克尔哈特尔的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 push -u origin main

其他回答

为了使用git,你必须

如果没有,那就用sudo

去除原点: Git远程删除原点

添加原点:

Git远程添加origin http://giturl

首先做一个:

git remote rm origin

然后

git remote add origin https://github.com/your_user/your_app.git

瞧!为我工作!

如果你得到一个类似“错误:远程源已经存在”的错误。 然后,请尝试以下命令删除已经存在的远程源

git remote remove origin

然后使用你的命令

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

如果您不想删除现有的远程记录,请更新它

git remote set-url <REMOTE-NAME> <NEW-URL>

然后使用你的命令

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

如果要重命名现有项目,请使用以下命令

git remote rename <old-name> <new-name>

如果要将原始远程重命名为backup。你只需运行:

git remote rename origin backup

谢谢你! !

我在远程推送代码时,在Bitbucket中面临问题

遵循以下步骤:

步骤1:更新现有的远程

git remote set-url origin https://pratik@bitbucket.org/pratik/demoapp.git

步骤2:您可以使用此命令强制使用本地存储库对服务器进行更改。远程回购代码将被本地回购代码取代。

git push -f origin master

-f通常,该命令拒绝更新不是用来覆盖它的本地引用的祖先的远程引用。

$ 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