推送到不同的 git 仓库

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

Pushing to a different git repo

gitgithub

提问by The worm

I have a repo called react. I cloned it into a different repo locally called different-repo.

我有一个名为react. 我将它克隆到本地名为different-repo.

How can I then get different-repoto push remotely to different-repo because currently it is pushing to react.

我怎样才能different-repo远程推送到不同的仓库,因为目前它正在推送到react.

Effectively I want to clone many times from reactinto different named repos but then when i push from those repos they push to their own repo.

实际上,我想从react不同的命名存储库中多次克隆,但是当我从这些存储库推送时,它们会推送到他们自己的存储库。

回答by math2001

You have to add an other remote. Usually, you have an originremotes, which points to the github (maybe bitbucket) repository you cloned it from. Here's a few example of what it is:

您必须添加另一个remote. 通常,您有一个origin遥控器,它指向您从中克隆它的 github(可能是 bitbucket)存储库。以下是它的一些示例:

  • https://github.com/some-user/some-repo(the .gitis optional)
  • [email protected]:some-user/some-repo(this is ssh, it allows you to push/pull without having to type your ids every single time)
  • C:/some/folder/on/your/computerYes! You can push to an other directory on your own computer.
  • https://github.com/some-user/some-repo(这.git是可选的)
  • [email protected]:some-user/some-repo(这是 ssh,它允许您推/拉而不必每次都输入您的 ID)
  • C:/some/folder/on/your/computer是的!您可以推送到您自己计算机上的其他目录。

So, when you

所以,当你

$ git push origin master

originis replaced with it's value: the url

origin被替换为它的值:url

So, it's basically just a shortcut. You could type the url yourself each time, it'd do the same!

所以,它基本上只是一个捷径。你可以每次都自己输入网址,它会做同样的事情!

Note: you can list all your remotes by doing git remote -v.

注意:您可以remote通过执行列出您所有的s git remote -v

For your problem

对于您的问题

How can I then get different-repo to push remotely to different-repo because currently it is pushing to react.

我怎样才能让不同的回购远程推送到不同的回购,因为目前它正在推动做出反应。

I'm guessing you want to create a second repository, right? Well, you can create an other remote(or replace the current origin) with the url to this repo!

我猜您想创建第二个存储库,对吗?好吧,您可以使用此 repo 的 url创建其他remote(或替换当前origin)!

Add an other remote— recommended

添加其他remote— 推荐

git remote add <remote-name> <url>

So, for example:

因此,例如:

$ git remote add different-repo https://github.com/your-username/your-repo

And then, just

然后,只要

$ git push different-repo master

Change the originremote

改变 originremote

git remote set-url <remote-name> <url>

So

所以

git remote set-url origin https://github.com/your-username/your-repo

回答by Shivkumar kondi

Here different-repois the first repo from which you created/cloned the child repo react

这里不同的回购是您创建/克隆子回购反应的第一个回购

So by default child repo react will have its default remoteas different-repo where you can push/pull changes.

因此,默认情况下,子 repo react 将其默认远程作为不同的 repo,您​​可以在其中推送/拉取更改。

Here child repo will maintain all the commit history of parent repo within its .git folder

这里子仓库将在其 .git 文件夹中维护父仓库的所有提交历史

If you want to push the changes to different repo from this react repo then add another remote(you can add as many as remotes here and also can delete the old remotes)

如果您想将更改从这个 react repo 推送到不同的 repo,然后添加另一个遥控器(您可以在此处添加尽可能多的遥控器,也可以删除旧遥控器)

Add new Remote to react

添加新的遥控器以做出反应

git remote add <remote-name> <url>

If you want to remove the old remote

如果你想删除旧的遥控器

git remote remove <remote_name>