我试图按照迈克尔哈特尔的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 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 remote set-url origin git@github.com:ppreyer/first_app.git
长版:
正如错误消息所示,已经有一个配置了相同名称的远程服务器。因此,您可以使用不同的名称添加新的远程设备,如果不需要的话,也可以更新现有的远程设备。
要添加一个新的远程,例如,调用github而不是origin(显然已经存在于您的系统中),执行以下操作:
$ git remote add github git@github.com:ppreyer/first_app.git
记住,尽管在教程中你看到“起源”,你应该把它换成“github”。例如$ git push origin master现在应该是$ git push github master。
但是,如果你想查看已经存在的原始远程是什么,你可以执行$ git remote -v。如果你认为这是由于一些错误,你可以这样更新它:
$ git remote set-url origin git@github.com:ppreyer/first_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
谢谢你! !
$ 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
我在远程推送代码时,在Bitbucket中面临问题
遵循以下步骤:
步骤1:更新现有的远程
git remote set-url origin https://pratik@bitbucket.org/pratik/demoapp.git
步骤2:您可以使用此命令强制使用本地存储库对服务器进行更改。远程回购代码将被本地回购代码取代。
git push -f origin master
-f通常,该命令拒绝更新不是用来覆盖它的本地引用的祖先的远程引用。
不要注意这个错误,这样写:
Git push -u origin main