简体   繁体   中英

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.

Basically, my team is starting a new project in our own git repo which will have other github projects as dependencies. 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. 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> . 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 . from root , doing git status -s would not show the files in the GitHub directories as added. 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. This is assuming the root folder you mention is not a git repo itself. 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. You will also have to add another upstream remote in the repo to pull changes from the original github repo.

If the the root folder is a git repo, then setting each folder inside upstream to be a git submodule is the best option. 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. 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.

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. And pull the update from the github repo. Detail steps as below:

1.Fork the repo you want. Open the github repo -> click fork button -> copy the fork repo URL.

2.Work with your repo as below:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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