如何将只读git克隆从github转换为分叉git [英] How to convert a readonly git clone from github to a forked one

查看:159
本文介绍了如何将只读git克隆从github转换为分叉git的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不时遇到这个问题。

假设我没有阅读rails的源代码,因为我遇到了一些问题。

p>

  git clone git://github.com/rails/rails.git 

在研究过程中,我测试了一些东西,现在我有一个解决方案,我希望Rails核心团队去看看。



请记住,当我克隆时,我没有克隆分支版本,而是只读版本。

>

这不是我反对分叉。它只是有时我想我只是去浏览,然后我想添加一些东西。

当你克隆一个repo时,它会自动设置一个名为 origin 的远程,它指向您已克隆的回购。这现在指向上游Rails项目,但您需要创建自己的分支,然后设置一个指向该分支的远程设备,以便将其推送到该分支。



第一步是点击上游GitHub项目页面上的Fork按钮(图片来自;请参阅那里的文档以了解如何做到这一点。但是,如果您只有一个或几个小补丁,那么Rails团队宁愿您创建一张灯塔票并附上你的补丁;有关更多信息,请参阅贡献Rails 的指示信息。



编辑下面是一个表示发生了什么的图表。你所做的只是克隆上游导轨回购;所以现在你在自己的机器上有自己的repo,它指的是 git://github.com/rails/rails.git 作为 origin

 
Github:git://github.com/rails/rails.git
^
|
Remotes:origin
|
你的机器:rails /

如果你分叉并克隆你的fork,你会得到下面的结果:


$ b

 
Github:git://github.com/rails/rails.git< - git@github.com:nadal / rails.git
^
|
Remotes:origin
|
您的机器:rails /

如果您按照我的指示操作,那么您将获得以下内容:

 
Github:git://github.com/rails/rails.git< - git@github.com:nadal / rails.git
^ ^
| |
远程:上游来源
| |
您的机器:\ ------------------------------- rails /

这就像分叉得到的版本,除了它还有一个上游远程,所以你可以跟踪官方更改并将它们合并到您的代码中(如果您创建了分支版本,则可能还需要添加上游远程)。


From time to time I encounter this issue.

Let's say that I did following to read the source code of rails because I am running into some issues.

git clone git://github.com/rails/rails.git

During the research I tested something and now I have a fix I would like rails core team to take a look at. How do I push my changes to a forked version of rails.

Remember when I cloned, I did not clone a forked version but a read-only version.

It is not that I am opposed to forking. It is just that sometimes I think I am just going to browse then I want to add something.

解决方案

When you clone a repo, it automatically sets up a remote called origin which refers to the repo that you have cloned. This is now pointing to the upstream Rails project, but what you need is to create your own fork that you can push to, and then set up a remote that points there so you can push to it.

The first step is to click the "Fork" button on the upstream GitHub project page (picture from GitHub instructions on forking):

Once you've done that, find and copy the URL for that repo. Make sure you use the SSH URL, which has read and write access. It should be something like git@github.com:nadal/rails.git, assuming your user name is nadal.

Now you can create the remote, which allows Git to keep track of a remote repository, pulling from it or pushing to it depending on the access you have. You can choose to either replace origin with the one that you will push to (which is how many people have it set up), or leave origin pointing to upstream and instead create a new remote. I'll show how to do the first setup; the second should be easy to figure out.

To change origin to point to your fork on GitHub, you will probably want to keep the upstream branch around somewhere, so rename it to upstream:

git remote rename origin upstream

Now create a new remote pointing to your fork:

git remote add -f origin git@github.com:nadal/rails.git

And now you should be able to push to your new fork:

git push origin master

Once you are happy with the changes you've pushed up to GitHub, and would like someone from the Rails team to look at it, you have two choices. One is to send a pull request using GitHub; see the docs there for how to do that. If you only have one or a few small patches, however, the Rails team would prefer that you create a Lighthouse ticket and attach you patch; see the instructions on contributing to Rails for more information.

edit Here's a diagram to indicate what's going on. What you have done is simply clone the upstream rails repo; so now you have your own repo on your own machine, which refers to git://github.com/rails/rails.git as origin:

Github:    git://github.com/rails/rails.git
                    ^
                    |
Remotes:          origin
                    |
Your machine:     rails/

Here's what you get if you forked and then clone your fork:

Github:    git://github.com/rails/rails.git <-- git@github.com:nadal/rails.git
                                                           ^
                                                           |
Remotes:                                                origin
                                                           |
Your machine:                                           rails/

If you follow my instructions, here is what you will get:

Github:    git://github.com/rails/rails.git <-- git@github.com:nadal/rails.git
                        ^                                  ^
                        |                                  |
Remotes:            upstream                            origin
                        |                                  |
Your machine:           \-------------------------------rails/

Which is just like the version that you get by forking, except that it also has an upstream remote so you can track official changes and merge them in to your code (if you had created the forked version, you would probably want to add the upstream remote as well).

这篇关于如何将只读git克隆从github转换为分叉git的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆