问题
I have created a branch in my GitHub repo: https://github.com/markmnl/FalconUDP, so there are now two branches: "master" and "single-threaded". I realise now I will never want to merge "single-threaded" back into "master" and want to maintain each branch separately independently of one another, though from time-to-time I will want to cherry pick bits of code from one into the other.
It would be disastrous should the branches be accidentally merged (though not catastrophic of course since I can always go back - it being in source control).
It strikes me what I should have done is fork the project into another repo. (That way I can still do the cherry picking with Pull Requests).
What should I do now?
回答1:
I guess your question is specifically: how to create a fork of your own project in the same user account in GitHub. You cannot use the user interface of the website, but you can create a new repository and push the relevant branches to it:
Create new repo, completely empty, without even a README https://github.com/new
Add the new repo as a new remote in your local clone of the original project, let's call this remote
fork
for example:git remote add fork NEW_REPO_URL
Push your
single-threaded
branch to it:git push -u fork single-threaded
Delete this branch from the original project, assuming your remote is called
origin
:git push origin :single-threaded
回答2:
Here's how I would do it:
- Fork FalconUDP into a new repository (using the fork feature on GitHub)
- Clone the new repository (
FalconUDP-st
?) locally - merge the
single-threaded
branch back intomaster
- delete the
single-threaded
branch - push back to
FalconUDP-st
on GitHub
You can issue pull requests on the GitHub website, or you can just cherry pick across your local clones.
回答3:
If you really want to fork, the way would be:
- Clone FalconUDP
- in the clone, checkout single-threaded branch
Now you have two options:
a) new remote repo
- Create new repo
- Add it as remote to cloned repo, call it, let's say "new-remote"
git push single-threaded new-remote/master
- New repo has contents of single-threaded as master
b) Local repo
- delete branch master
- checkout from branch single-threaded into new branch master
来源:https://stackoverflow.com/questions/20450537/how-to-turn-a-git-branch-into-fork