我的项目在GitHub上的某个位置:git@github.com:myname/oldrep.git
。
现在我想将所有代码推送到另一个位置上的新存储库,git@github.com:newname/newrep.git
。
我使用了以下命令:
git remote add origin git@github.com:myname/oldrep.git
但是我收到了这个错误信息:
致命错误:远程 origin 已经存在。
我的项目在GitHub上的某个位置:git@github.com:myname/oldrep.git
。
现在我想将所有代码推送到另一个位置上的新存储库,git@github.com:newname/newrep.git
。
我使用了以下命令:
git remote add origin git@github.com:myname/oldrep.git
但是我收到了这个错误信息:
致命错误:远程 origin 已经存在。
你会看到这个错误是因为 "origin" 不可用。"origin" 是命令中的一个惯例,而非命令的一部分。"origin" 是远程代码库的本地名称。
例如,您也可以编写:
git remote add myorigin git@github.com:myname/oldrep.git
git remote add testtest git@github.com:myname/oldrep.git
请参阅手册:
http://www.kernel.org/pub/software/scm/git/docs/git-remote.html
要删除远程存储库,请输入:
git remote rm origin
再次提醒,如果你想要删除"upstream"远程仓库,"origin"是指代远程仓库的名称:
git remote rm upstream
git push -u origin master --force
- Ronnie Roystongit remote rm origin
对我有用。 - kkgarg前面的解决方案似乎忽略了源,他们只建议使用另一个名称。当你想要使用git push origin
时,请继续阅读。
问题出现是因为按照错误的Git配置顺序进行操作。您可能已经在.git配置文件中添加了'git origin'。
您可以使用以下行更改Git配置中的远程origin:
git remote set-url origin git@github.com:username/projectname.git
这个命令设置一个新的URL,以便将Git存储库推送到其中。重要的是填入你自己的用户名和项目名称。
git remote set-url origin https://github.com/<username>/<projectname>.git
- Justin Liugit remote rm origin
方法1->
由于原始数据已经存在,因此需要将其删除。
git remote rm origin
git remote add origin https://github.com/USERNAME/REPOSITORY.git
METHOD2->
可以使用git remote set-url命令更改现有的远程仓库URL。
如果您正在更新以使用HTTPS,则:
git remote set-url origin https://github.com/USERNAME/REPOSITORY.git
如果您正在更新以使用SSHgit remote set-url origin git@github.com:USERNAME/REPOSITORY.git
如果尝试更新不存在的远程,您将收到错误消息。所以要小心。METHOD3 -> 使用git remote rename命令重命名现有的远程。一个现有的远程名称,例如origin。git remote rename origin startpoint
# Change remote name from 'origin' to 'startpoint'
验证远程的新名称 ->
git remote -v
如果您是Git新手,请尝试这个教程->
你可以在文本编辑器中简单地编辑你的配置文件。
在 ~/.gitconfig
中,你需要输入类似以下内容:
[user]
name = Uzumaki Naruto
email = myname@example.com
[github]
user = myname
token = ff44ff8da195fee471eed6543b53f1ff
在你的代码库的配置文件oldrep/.git/config
中:
[remote "github"]
url = git@github.com:myname/oldrep.git
push = +refs/heads/*:refs/heads/*
push = +refs/tags/*:refs/tags/*
如果你的仓库配置文件中有一个远程部分,且URL匹配,你只需要添加推送(push)配置。如果你使用公共URL进行拉取(fetching),你可以将推送(push)的URL放入'pushurl'中(警告:这需要刚发布的Git 1.6.4版本)。
我曾经也遇到这个问题,做了一些研究后解决了:
Git Shell
。这将打开一个包含Git命令的PowerShell。cd C:\path\to\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://user@bitbucket.org/team-or-user-name/myproject.git (fetch)
origin https://user@bitbucket.org/team-or-user-name/myproject.git (push)
If it's not connected, it might show origin
only.
Now remove the remote repository from the local repository by using
git remote rm origin
Check again with git remote -v
, as in step 4. It should show origin
only, instead of the fetch and push path.
Now that your old remote repository is disconnected, you can add the new remote repository. Use the following to connect to your new repository:
注意:如果您正在使用Bitbucket,则首先需要在Bitbucket上创建一个项目。创建后,Bitbucket将显示所有必需的Git命令,以将存储库推送到远程,这些命令看起来类似于下面的代码片段。但是,这对其他存储库也适用。
cd /path/to/my/repo # If you haven't done that yet.
git remote add mynewrepo https://user@bitbucket.org/team-or-user-name/myproject.git
git push -u mynewrepo master # To push changes for the first time.
这就是全部。
git remote rm origin
git remote -v
不会显示任何仓库名称
git remote add origin git@github.com:username/myapp.git
git push origin master
它将开始创建新分支的过程。
您可以看到您的工作已经被推送到Github。
git remote rm origin
git remote add origin git@github.com:username/myapp.git
git remote set-url origin https://github.com/USERNAME/NEW_REPO.git
git push --set-upstream origin main
您无需删除现有的“origin”远程,只需使用名称不同于“origin”的远程添加即可,例如:
git remote add github git@github.com:myname/oldrep.git
git remote add origin2 ....
即可。但是,如果您只需要推送一次而不修改存储库配置,则可以简单地执行git push git@github.com:user/another-project.git master:master
。 - ccpizza