markmnl
markmnl

Reputation: 11426

How to turn a git branch into fork?

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?

Upvotes: 9

Views: 6383

Answers (3)

janos
janos

Reputation: 124646

If I understand correctly, you want to create a fork a project within the same user account or organization in GitHub. This seems explicitly unsupported by GitHub, explained their article Alternatives to forking into the same account.

Something you can do, and might be suitable for your purpose, is create a new repository and push the single-threaded branch to it:

  1. Create new repo, completely empty (do NOT add README or other files): https://github.com/new

  2. In your local clone of the original repo, add the new repo as a new remote, let's call this remote repo2 for example:

     git remote add repo2 NEW_REPO_URL
    
  3. Push your single-threaded branch to the new repo (repo2 remote):

     git push -u repo2 single-threaded
    
  4. Delete this branch from the original project, assuming your remote is called origin:

     git push origin :single-threaded
    

This is not the same thing as the fork feature on GitHub. The fork feature on GitHub would show on the UI of repo2 a link to the original repo. According to the article I linked above, I think you cannot have that effect. If you want to bring attention to the existence of these two repos, and how to use them, I think your best option is to document it.

Upvotes: 8

p_l
p_l

Reputation: 1179

If you really want to fork, the way would be:

  1. Clone FalconUDP
  2. in the clone, checkout single-threaded branch

Now you have two options:

a) new remote repo

  1. Create new repo
  2. Add it as remote to cloned repo, call it, let's say "new-remote"
  3. git push single-threaded new-remote/master
  4. New repo has contents of single-threaded as master

b) Local repo

  1. delete branch master
  2. checkout from branch single-threaded into new branch master

Upvotes: 0

Ben Collins
Ben Collins

Reputation: 20686

Here's how I would do it:

  1. Fork FalconUDP into a new repository (using the fork feature on GitHub)
  2. Clone the new repository (FalconUDP-st?) locally
  3. merge the single-threaded branch back into master
  4. delete the single-threaded branch
  5. 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.

Upvotes: 0

Related Questions