远程源已经存在于“git push”上 到一个新的存储库

发布于 2024-07-30 10:10:46 字数 647 浏览 6 评论 0原文

我的项目位于 GitHub 上的某个位置,[电子邮件受保护]:myname/oldrep.git

现在我想将所有代码推送到其他位置的新存储库, [电子邮件受保护]:newname/newrep.git

我使用了命令:

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

但我收到了这个:

致命:远程源已存在。

I have my project on GitHub at some location, [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.

I used the command:

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

but I am receiving this:

fatal: remote origin already exists.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(22

心是晴朗的。 2024-08-06 10:10:46

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

例如,您也可以编写:

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

请参阅手册:

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

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

git remote rm origin

同样,“origin”是远程存储库的名称(如果您想要)
删除“上游”遥控器:

git remote rm upstream

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.

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

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
绮烟 2024-08-06 10:10:46

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

出现此问题的原因是 Git 配置顺序错误。 您可能已经将“git origin”添加到您的 .git 配置中。

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

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

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

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.

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

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

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 username and projectname

痕至 2024-08-06 10:10:46

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

git remote rm origin

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

git remote rm origin
雾里花 2024-08-06 10:10:46

方法1->

由于原点已存在,请将其删除。

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

方法2->

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

如果您要更新为使用 HTTPS

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

如果您要更新为使用 SSH

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

如果尝试更新远程不存在,您将收到错误。 所以要小心。

方法3->

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

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

验证遥控器的新名称->

git remote -v

如果是 Git 新手,请尝试本教程 ->

尝试一下GIT 教程

METHOD1->

Since origin already exist remove it.

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

METHOD2->

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

If you're updating to use HTTPS

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

If you're updating to use 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->

Use the git remote rename command to rename an existing remote.
An existing remote name, for example, 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->

TRY GIT TUTORIAL

帅气称霸 2024-08-06 10:10:46

您只需在文本编辑器中编辑配置文件即可。

~/.gitconfig 中,您需要放入类似以下内容:

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

[github]
        user = myname
        token = ff44ff8da195fee471eed6543b53f1ff

oldrep/.git/config 文件中(在配置中)文件):

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

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

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

In the ~/.gitconfig you need to put in something like the following:

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

[github]
        user = myname
        token = ff44ff8da195fee471eed6543b53f1ff

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

[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).

后知后觉 2024-08-06 10:10:46

我遇到了同样的问题,经过一些研究后,我解决了这个问题:

  1. 下载 GitHub for Windows,或者使用类似的东西,其中包括一个外壳。
  2. 从任务菜单中打开 Git Shell。 这将打开一个包含 Git 命令的电源 shell。
  3. 在 shell 中,切换到旧存储库,例如 cd C:\path\to\old\repository。
  4. 显示旧存储库的状态。
  • 输入git remote -v以获取远程获取和推送的远程路径。 如果您的本地存储库连接到远程存储库,它将显示如下内容:

     来源 https://[电子邮件受保护]/团队或用户名/myproject.git(获取) 
       来源 https://[电子邮件受保护]/team-or-user-名称/myproject.git(推送) 
      
  • 如果未连接,则可能仅显示origin

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

    git 远程 rm 原点 
      
  2. ,如步骤 4 所示。它应该仅显示 origin,而不是获取和推送路径。

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

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

cd /path/to/my/repo # If you haven't done that 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.

就是这样。

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

  1. Download GitHub for Windows, or use something similar, which includes a shell.
  2. Open the Git Shell from the 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 the status of the old repository.
  • Type git remote -v to get the remote path for fetch and push remote. If your local repository is connected to a remote, it will show something like this:

     origin  https://[email protected]/team-or-user-name/myproject.git (fetch)
     origin  https://[email protected]/team-or-user-name/myproject.git (push)
    
  • If it's not connected, it might show origin only.

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

    git remote rm origin
    
  2. Check again with git remote -v, as in step 4. It should show origin only, instead of the fetch and push path.

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

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 as well.

cd /path/to/my/repo # If you haven't done that 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.

混浊又暗下来 2024-08-06 10:10:46
  1. git 远程 rm 原点

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

  3. git Remote add origin [email protected ]:用户名/myapp.git

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

  1. git remote rm origin

  2. git remote -v
    It will not display any repository name

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

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

摘星┃星的人 2024-08-06 10:10:46

下面的两个命令应该有助于设置。

git remote set-url origin https://github.com/USERNAME/NEW_REPO.git
    
git push --set-upstream origin main

The below two commands should help set up.

git remote set-url origin https://github.com/USERNAME/NEW_REPO.git
    
git push --set-upstream origin main
や三分注定 2024-08-06 10:10:46
git remote rm origin
git remote add origin [email protected]:username/myapp.git
git remote rm origin
git remote add origin [email protected]:username/myapp.git
小清晰的声音 2024-08-06 10:10:46

您不必删除现有的“origin”远程,只需使用“origin”以外的名称进行远程添加,例如

git remote add github [电子邮件受保护]:myname/oldrep.git

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

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

度的依靠╰つ 2024-08-06 10:10:46

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

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

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

I had the same problem when I first set up using 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
厌味 2024-08-06 10:10:46

您应该将远程存储库的名称更改为其他名称。

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

我认为

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

这应该有效。

是的,这些用于存储库初始化和添加新的远程。 只是换了个名字而已。

You should change the name of the remote repository to something else.

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

to

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

I think this should work.

Yes, these are for repository init and adding a new remote. Just with a change of name.

肩上的翅膀 2024-08-06 10:10:46

您还可以在 REPOHOME/.git/config 文件中更改要推送到的存储库名称

(其中 REPOHOME 是存储库本地克隆的路径)。

You could also change the repository name you wish to push to in the REPOHOME/.git/config file

(where REPOHOME is the path to your local clone of the repository).

话少情深 2024-08-06 10:10:46

您需要检查来源,如果不存在则添加。

if ! git config remote.origin.url >/dev/null; then
    git remote add origin [email protected]:john/doe.git
fi

创建文件 check.sh,粘贴脚本更新您的 git 存储库 URL 并运行 ./check.sh

You need to check the origin and add if not exists.

if ! git config remote.origin.url >/dev/null; then
    git remote add origin [email protected]:john/doe.git
fi

Create file check.sh, paste the script update your git repository URL and run ./check.sh.

裂开嘴轻声笑有多痛 2024-08-06 10:10:46

我有同样的问题,但我找到了解决方案。 基本上,“起源”是克隆项目的另一个名称。 现在错误

fatal: remote origin already exists.

实际上意味着原点已经存在。 因此,要解决这个问题,我们的目标应该是消除它。
为此目的:

git remote rm origin

现在再次添加它

git remote add origin https://github.com/__enter your username here__/__your repositoryname.git__

这确实解决了我的问题。

I had the same issue but I found the solution to it. Basically "origin" is another name from where your project was cloned. Now the error

fatal: remote origin already exists.

LITERALLY means origin already exists. And hence to solve this issue, our goal should be to remove it.
For this purpose:

git remote rm origin

Now add it again

git remote add origin https://github.com/__enter your username here__/__your repositoryname.git__

This did fix my issue.

橪书 2024-08-06 10:10:46

当您忘记进行第一次提交时,也可能会发生这种情况。

This can also happen when you forget to make a first commit.

尬尬 2024-08-06 10:10:46

我自己刚刚遇到这个问题,我只是通过删除原点来删除它。
origin,则此命令会删除 origin,请尝试执行此命令。

git remote rm origin

如果您已将远程存储库添加为

I just faced this issue myself and I just removed it by removing the origin.
the origin is removed by this command

git remote rm origin

if you've added the remote repo as origin try implementing this command.

纸短情长 2024-08-06 10:10:46

尝试删除第一个现有的源,为了查看哪个现有源已在 bash 中注册,您可以触发以下命令。

 git remote -v 

在您知道哪个版本的 origin 已在 bash 中注册后,您可以通过触发以下命令来删除现有的 origin

git remote rm origin

一旦您删除了现有的 origin,您可以在您的情况下通过触发以下命令来添加新的 origin ..

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

一旦您在 git 中添加了您的 origin,那么您可以将本地提交推送到远程源

git push -u origin --all

Try to remove first existing origin, In order to see the which existing origin has registered with bash you can fire below command.

 git remote -v 

after you know the which version of origin has register with bash then you can remove existing origin by firing below command

git remote rm origin

Once you removed existing origin you can add new origin by firing below command in you case ..

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

Once you add your origin in git, then you can push your local commit to remote origin

git push -u origin --all
山人契 2024-08-06 10:10:46

步骤:1

git remote rm origin

步骤:2

git remote add origin enter_your_repository_url

示例:

git remote add origin https://github.com/my_username/repository_name.git

Step:1

git remote rm origin

Step:2

git remote add origin enter_your_repository_url

Example:

git remote add origin https://github.com/my_username/repository_name.git
楠木可依 2024-08-06 10:10:46

如果你想在 github 中创建一个具有相同项目的新存储库,并且之前的 Remote 不允许你这样做,在这种情况下,首先删除 github 上的该存储库,那么你只需删除 .git 文件夹C: \Users\Shiva\AndroidStudioProjects\yourprojectname\.git 删除该文件夹,(确保您单击隐藏文件,因为该文件夹是隐藏的)

同时单击 android studio 设置->版本控制中的减号(删除按钮)
单击此处从 android 中删除版本控制 然后您将能够创建新的存储库。

if you want to create a new repository with the same project inside the github and the previous Remote is not allowing you to do that in that case First Delete That Repository on github then you simply need to delete the .git folder C:\Users\Shiva\AndroidStudioProjects\yourprojectname\.git delete that folder,(make sure you click on hidden file because this folder is hidden )

Also click on the minus(Remove button) from the android studio Setting->VersionControl
click here for removing the Version control from android And then you will be able to create new Repository.

早茶月光 2024-08-06 10:10:46

试试这个命令,它对我有用。

rm -rf .git/

Try this command it works for me.

rm -rf .git/

绝情姑娘 2024-08-06 10:10:46
git remote rm origin 

进而

git push -f 
git remote rm origin 

and then

git push -f 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文