8

How do I fork a repo in my organization into the same organization so that I can regularly sync the fork with the upstream repository?

In this StackOverflow question Copy/fork a git repo on github into same organization the asker wanted to create two separate disconnected repos one which was cloned from the other.

How do I create a forked project which multiple people will be able to see and work on from the 1 organization?


Further background

One of the repos in our organization is a template framework which we use to build dozens of other applications. I am looking to solve the issue of when we add updates / patches to this template, the other repos are able to pull these changes.

I don't want to fork to my individual account as that would be awful visibility for the organization in the future.

4
  • If I understood correctly you need a mirror repository. Is it correct? Otherwise same repo from organization and individual forks in respective namespace should be sufficient to work on same repository. Basically pull request flow will enable all the developers to work on same repository from the organization. Commented Aug 18, 2017 at 4:21
  • @RishikeshDarandale Possibly? I need a solution which yes will mirror, but then when I make changes to the original, I can pull these into the mirrored repo. Sorry but I don't understand what you mean by: "pull request flow will enable all the developers to work on same repository from the organization"
    – Zze
    Commented Aug 18, 2017 at 4:27
  • Can you please share more about your template repository? Can't that be an artifact which should follow it's own release cycle and released artifacts can be used in child projects as a dependency? The pull request flow will be helpful for a single repository with individual forks. Commented Aug 18, 2017 at 4:36
  • @RishikeshDarandale Let me get back to you about this, I need to go and look into what you're proposing before I know if I can make it work or not.. Thanks for the comments.
    – Zze
    Commented Aug 18, 2017 at 4:39

2 Answers 2

10

I was facing a similar situation and came across this solution for cloning completed separated projects you listed. With some simple editions, you can send branches across repositories and sync them manually thru pull requests.

I already had the cloned repository from the original, but if you don't have it, follow @larsks answer to clone and create a copy of the repo:

$ git clone [email protected]:org/myrepo-original myrepo-new
$ cd myrepo-new
$ git remote set-url origin [email protected]:org/myrepo-new
$ git push origin master

After doing that, go back to the directory containing the original repository (the one where origin still points to [email protected]:org/myrepo-original used in the example) and add a remote pointing to the cloned using the command:

$ git remote add cloned [email protected]:org/myrepo-new

Your original repo should look like this now:

$ git remote -v

origin  [email protected]:org/myrepo-original (fetch)
origin  [email protected]:org/myrepo-original (push)
cloned  [email protected]:org/myrepo-new (fetch)
cloned  [email protected]:org/myrepo-new (push)

After this, you can push branches containing the stuff you want to the cloned repo and create pull requests to better visualize the contents and merges.

Let's say you want to update the master from the cloned repository with the master from original one:

$ cd myrepo-original
$ git checkout master
$ git checkout -b master-original
$ git push cloned master-original

And from myrepo-new on the GitHub interface create the PR using the base as master and compare as master-original.

Note: Although I think this would solve your problem, I would recommend based on the Further background you provided to research the possibility and turn your core/template repo on a submodule. In my opinion this makes it easier to update the core application between repos instead of "sending" branches cross repositories. =)

1
  • Thanks for the answer, I will check this out!
    – Zze
    Commented Dec 22, 2017 at 21:32
3

Github now allows intra-organization forks.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.