简体   繁体   English

我如何将github项目叉到github外部的git repo上?

[英]How do I fork a github project to a git repo outside github?

I've never worked with git before this project I'm trying to get going, so please bear with me. 在我尝试开始该项目之前,我从未与git合作,所以请耐心等待。

Basically, my team is starting a new project in our own git repo which will have other github projects as dependencies. 基本上,我的团队正在我们自己的git repo中启动一个新项目,该项目将具有其他github项目作为依赖项。 We expect we will have to do edits on those dependencies which we want to push back to our own repo so everyone on the team can sync them. 我们希望我们必须对那些我们想回退到我们自己的仓库的依赖项进行编辑,以便团队中的每个人都可以同步它们。 We would also like to take updates to the dependencies from the original GitHub repo as we would like to eventually push back the changes in our repo to GitHub. 我们还希望对原始GitHub存储库中的依赖项进行更新,因为我们最终希望将存储库中的更改推回GitHub。 Does this make sense so far? 到目前为止,这有意义吗?

Ok, so the way I wanted to lay out our project is something like follows: 好的,所以我要布置我们的项目的方式如下:

root
|- src                    <- Our code goes here
|- upstream               <- GitHub dependencies go under here
   |- GitHub project A
   |- GitHub project B

So I thought the way one goes about doing this is to for each GitHub dependency, git clone the GitHub repo to the desired directory, and then git remote set-url origin <our repo url> and then git remote add upstream <original github url> . 所以我认为这样做的方法是针对每个GitHub依赖项, git clone将GitHub存储git clone到所需目录,然后git remote set-url origin <our repo url> ,然后git remote add upstream <original github url> I thought then I'd be able to make changes, add, commit and finally push to our repo. 我认为然后我就可以进行更改,添加,提交并最终推送到我们的仓库。 And when desired, pull from the upstream remote to keep stuff up to date. 并且在需要时,从上游遥控器拉动以保持最新状态。

Unfortunately this didn't quite work out, after I did git add . 不幸的是,在我执行git add .之后,这还没有完全解决git add . from root , doing git status -s would not show the files in the GitHub directories as added. root ,执行git status -s不会显示已添加的GitHub目录中的文件。 Doing a commit and push put things in what looked like a half baked state and then I started stressing out because I have no idea what I'm doing. 进行提交和推送会将事情置于半熟状态,然后我开始感到压力,因为我不知道自己在做什么。

So if anyone can share some help I would greatly appreciate it, but please talk to me like I'm five years old. 因此,如果有人可以分享一些帮助,我将不胜感激,但是请像我五岁那样与我联系。

Your strategy would work but only if you actually have upstream write permissions which apparently you don't. 您的策略将起作用,但前提是您实际上只有上游写权限,而您显然没有。 Since only the dependencies need to be forked, and if keeping the repos in Github rather than an external system is an option, then I would suggest doing that. 由于只需要派生依赖项,并且如果将存储库保存在Github中而不是外部系统中是一种选择,那么我建议这样做。 This is assuming the root folder you mention is not a git repo itself. 这是假设您提到的根文件夹本身不是git repo。 If yes read on, else skip to the next paragraph. 如果是,请继续阅读,否则请跳至下一段。

In that case, you can set the upstream to your forked repo in Github and then open a PR from there to the original repo, while keeping your own (private?) repo as the origin remote. 在这种情况下,您可以在Github中将上游设置为分支仓库,然后从那里打开PR至原始仓库,同时保持自己的(私有?)仓库为origin仓库。 You will also have to add another upstream remote in the repo to pull changes from the original github repo. 您还必须在存储库中添加另一个上游远程服务器,以从原始github存储库中提取更改。

If the the root folder is a git repo, then setting each folder inside upstream to be a git submodule is the best option. 如果根文件夹是git repo,那么最好将上游的每个文件夹设置为git子模块 This way, you need not maintain three different versions of your repo(original, fork and in your upstream folder). 这样,您无需维护存储库的三个不同版本(原始版本,派生版本和上游文件夹中的版本)。 Instead, you can fork the repos in Github, and then refer to the forks from within the upstream folder. 相反,您可以在Github中分叉存储库,然后从上游文件夹中引用分叉。 Any changes to it can be added directly to the fork. 对它的任何更改都可以直接添加到派生中。 You can then open a pull request to the original repos from the fork via Github itself. 然后,您可以通过Github本身从fork打开对原始存储库的拉取请求。

I would also suggest renaming the upstream folder in your root to something else as it can be quite confusing as to what you are referring to. 我还建议将根目录中的上游文件夹重命名为其他名称,因为这可能会使您所指的内容混淆。

So you want to edit/pull upstream for your project, not to contribute to upstream itself. 因此,您想为项目编辑/拉动上游,而不是为上游本身做贡献。 For this way, you can fork this github repo, make change and push them to the fork one. 通过这种方式,您可以派生此github存储库,进行更改并将其推入派生库。 And pull the update from the github repo. 并从github仓库中获取更新。 Detail steps as below: 详细步骤如下:

1.Fork the repo you want. 1.fork你想要的回购。 Open the github repo -> click fork button -> copy the fork repo URL. 打开github repo->单击fork按钮->复制fork repo URL。

2.Work with your repo as below: 2.按以下方式处理您的仓库:

git clone <your repo URL>
cd <your repo name>
git submodule add <fork repo URL> upstream
cd upstream
git remote add real <URL of the github repo>
# edit commit changes for the dependence
git push origin  branchname  # push changes to the fork repo
git pull real branchname     # pull the update of branchname from the github repo
git push origin branchname   # push changes to the fork repo
cd ..
git commit
git push                     #push changes to your repo

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM