“git push”上已存在远程源到新存储库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1221840/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 06:49:55  来源:igfitidea点击:

Remote origin already exists on 'git push' to a new repository

gitgithubgit-pushgit-remote

提问by uzumaki naruto

I have my project on GitHub at some location, [email protected]:myname/oldrep.git.

我在 GitHub 上的某个位置有我的项目,[email protected]:myname/oldrep.git.

Now I want to push all my code to a new repository at some other location, [email protected]:newname/newrep.git.

现在我想将我的所有代码推送到其他位置的新存储库,[email protected]:newname/newrep.git.

I used the command:

我使用了命令:

git remote add origin [email protected]:myname/oldrep.git

but I am receiving this:

但我收到了这个:

fatal: remote origin already exists.

致命:远程源已经存在。

回答by MrHus

You are getting this error because "origin" is not available. "origin" is a convention not part of the command. "origin" is the local name of the remote repository.

您收到此错误是因为“来源”不可用。“origin”是一个约定,不是命令的一部分。“origin”是远程存储库的本地名称。

For example you could also write:

例如你也可以写:

git remote add myorigin [email protected]:myname/oldrep.git  
git remote add testtest [email protected]:myname/oldrep.git

See the manual:

看说明书:

http://www.kernel.org/pub/software/scm/git/docs/git-remote.html

http://www.kernel.org/pub/software/scm/git/docs/git-remote.html

To remove a remote repository you enter:

要删除远程存储库,请输入:

git remote rm origin

Again "origin" is the name of the remote repository if you want to remove the "upstream" remote:

如果要删除“上游”远程,“来源”再次是远程存储库的名称:

git remote rm upstream

回答by Hoetmaaiers

The previous solutions seem to ignore origin, and they only suggest to use another name. When you just want to use git push origin, keep reading.

之前的解决方案似乎忽略了起源,他们只建议使用其他名称。当您只想使用 时git push origin,请继续阅读。

The problem appears because a wrong order of Git configuration is followed. You might have already added a 'git origin' to your .git configuration.

出现问题是因为遵循了错误的 Git 配置顺序。您可能已经在 .git 配置中添加了“git origin”。

You can change the remote origin in your Git configuration with the following line:

您可以使用以下行更改 Git 配置中的远程源:

git remote set-url origin [email protected]:username/projectname.git

This command sets a new URL for the Git repository you want to push to. Important is to fill in your own usernameand projectname

此命令为要推送到的 Git 存储库设置新 URL。重要的是要填你自己的用户名项目名称

回答by ?zgür

If you have mistakenly named the local name as "origin", you may remove it with the following:

如果您错误地将本地名称命名为“origin”,您可以使用以下命令将其删除:

git remote rm origin

回答by shaurya uppal

METHOD1->

方法1->

Since origin already exist remove it.

由于原点已经存在删除它。

git remote rm origin
git remote add origin https://github.com/USERNAME/REPOSITORY.git

METHOD2->

方法2->

One can also change existing remote repository URL by ->git remote set-url

还可以通过 ->git remote set-url 更改现有的远程存储库 URL

If you're updating to use HTTPS

如果您要更新以使用 HTTPS

git remote set-url origin https://github.com/USERNAME/REPOSITORY.git

If you're updating to use SSH

如果您要更新以使用 SSH

git remote set-url origin [email protected]:USERNAME/REPOSITORY.git

If trying to update a remote that doesn't exist you will receive a error. So be careful of that.

如果尝试更新不存在的遥控器,您将收到错误消息。所以要小心。

METHOD3->

方法3->

Use the git remote rename command to rename an existing remote. An existing remote name, for example, origin.

使用 git remote rename 命令重命名现有遥控器。现有的远程名称,例如 origin。

git remote rename origin startpoint
# Change remote name from 'origin' to 'startpoint'

To verify remote's new name->

验证遥控器的新名称->

git remote -v

If new to Git try this tutorial->

如果刚接触 Git,请尝试本教程->

TRY GIT TUTORIAL

试用 Git 教程

回答by Jakub Nar?bski

You can simply edit your configuration file in a text editor.

您可以简单地在文本编辑器中编辑配置文件。

In the ~/.gitconfigyou need to put in something likethe following:

~/.gitconfig你需要把东西下面:

[user]
        name  = Uzumaki Naruto
        email = [email protected]

[github]
        user = myname
        token = ff44ff8da195fee471eed6543b53f1ff

In the oldrep/.git/configfile (in the configuration file of your repository):

oldrep/.git/config文件中(在存储库的配置文件中):

[remote "github"]
        url = [email protected]:myname/oldrep.git
        push  = +refs/heads/*:refs/heads/*
        push  = +refs/tags/*:refs/tags/*

If there is a remote section in your repository's configuration file, and the URL matches, you need only to add push configuration. If you use a public URL for fetching, you can put in the URL for pushing as 'pushurl' (warning: this requires the just-released Git version 1.6.4).

如果你的仓库的配置文件中有远程部分,并且 URL 匹配,你只需要添加推送配置。如果您使用公共 URL 进行获取,您可以将用于推送的 URL 输入为“pushurl”(警告:这需要刚刚发布的 Git 版本 1.6.4)。

回答by dev

  1. git remote rm origin

  2. git remote -vIt will not display any repository name

  3. git remote add origin [email protected]:username/myapp.git

  4. git push origin masterIt will start the process and creating the new branch. You can see your work is pushed to github.

  1. git remote rm origin

  2. git remote -v它不会显示任何存储库名称

  3. git remote add origin [email protected]:username/myapp.git

  4. git push origin master它将启动该过程并创建新分支。你可以看到你的工作被推送到了 github。

回答by mpelzsherman

You don't have to remove your existing "origin" remote, just use a name other than "origin" for your remote add, e.g.

您不必删除现有的“origin”遥控器,只需为您的遥控器添加“origin”以外的名称,例如

git remote add github[email protected]:myname/oldrep.git

git 远程添加github[email protected]:myname/oldrep.git

回答by Aayushi

git remote rm origin
git remote add origin [email protected]:username/myapp.git

回答by Michael

I got the same issue, and here is how I fixed it after doing some research:

我遇到了同样的问题,这是我在进行一些研究后修复它的方法:

  1. Download GitHub for Windowsor use something similar, which includes a shell
  2. Open the Git Shellfrom task menu. This will open a power shell including Git commands.
  3. In the shell, switch to your old repository, e.g. cd C:\path\to\old\repository
  4. Show status of the old repository

  5. Now remove the remote repository from local repository by using

    git remote rm origin
    
  6. Check again with step 4. It should show originonly, instead of the fetch and push path.

  7. Now that your old remote repository is disconnected, you can add the new remote repository. Use the following to connect to your new repository.

  1. 下载适用于 Windows 的 GitHub或使用类似的东西,其中包括一个 shell
  2. 打开Git Shell从任务菜单。这将打开一个包含 Git 命令的电源外壳。
  3. 在 shell 中,切换到旧的存储库,例如 cd C:\path\to\old\repository
  4. 显示旧仓库的状态

  5. 现在使用以下命令从本地存储库中删除远程存储库

    git remote rm origin
    
  6. 再次检查第 4 步。它应该origin只显示,而不是获取和推送路径。

  7. 现在您的旧远程存储库已断开连接,您可以添加新的远程存储库。使用以下命令连接到您的新存储库。

Note: In case you are using Bitbucket, you would create a project on Bitbucket first. After creation, Bitbucket will display all required Git commands to push your repository to remote, which look similar to the next code snippet. However, this works for other repositories, too.

注意:如果您使用 Bitbucket,您将首先在 Bitbucket 上创建一个项目。创建后,Bitbucket 将显示将您的存储库推送到远程所需的所有 Git 命令,这类似于下一个代码片段。但是,这也适用于其他存储库。

cd /path/to/my/repo # If haven't done yet
git remote add mynewrepo https://[email protected]/team-or-user-name/myproject.git
git push -u mynewrepo master # To push changes for the first time

That's it.

就是这样。

回答by Michael Murphy

I had the same problem when I first set up using Bitbucket.

当我第一次使用Bitbucket 进行设置时,我遇到了同样的问题。

My problem was that I needed to change the word origin for something self-defined. I used the name of the application. So:

我的问题是我需要更改自定义内容的词源。我使用了应用程序的名称。所以:

git remote add AppName https://[email protected]/somewhere/something.git