如何克隆GitHub存储库,然后将其作为源推送到新存储库? [英] How can I clone a GitHub repository, then push it to a new repository as origin?
问题描述
假设您在GitHub上拥有一个框架,并希望使用它来创建其他站点,所以您要:
Let's say you have a framework on GitHub and want to use it to create other sites, so you want to:
- 在本地克隆
- 更改
- 将其推送到新的存储库
这些是我目前对此的说明:
These are the instructions I currently have for this:
-
git clone https://github.com/yourname/framework.git newsite
-
cd新站点
- (进行更改)
- 在Github上,创建一个名为"newsite"的新存储库.
-
git remote add origin2 https://github.com/yourname/newsite.git
-
git push -u origin2 master
不幸的是,我不得不推送到 origin2
,否则它会回复到我原来不想要的原始框架.
I unfortunately have to push to origin2
otherwise it pushes back to my original framework, which I don't want, of course.
但这会导致我在将来的某个时候无意中将其推入原地的问题.
But this causes the problem that I may inadvertently push to origin at some time in the future.
如何使我的新存储库起源?
或者,当您要(1)克隆存储库,但(2)将其推送到其他存储库时,是否还有更简便的方法?
Or is there a more straight-forward way to do this when you want to (1) clone a repository, but (2) push it to a different repository?
推荐答案
如果您想同时更新抓取和推送URL,则指向相同的仓库
If you would want to update both fetch and push URL, pointing to same repo
git remote set-url origin <new-repo-url>
以下命令会将新存储库设置为默认存储库,仅推送.
Below command will set new repository as default repo to push only.
git remote set-url --push origin <new-repo-url>
如果需要通过上述命令取消推送网址设置
If need to unset the Push URL setup by above command
git remote set-url --delete --push origin <current-push-URL>
这篇关于如何克隆GitHub存储库,然后将其作为源推送到新存储库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!