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.

Vikas Yadav
  • 3,094
  • 2
  • 20
  • 21
Zze
  • 18,229
  • 13
  • 85
  • 118
  • 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. – Rishikesh Darandale Aug 18 '17 at 04: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 Aug 18 '17 at 04: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. – Rishikesh Darandale Aug 18 '17 at 04: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 Aug 18 '17 at 04:39

2 Answers2

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 git@github.com:org/myrepo-original myrepo-new
$ cd myrepo-new
$ git remote set-url origin git@github.com: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 git@github.com:org/myrepo-original used in the example) and add a remote pointing to the cloned using the command:

$ git remote add cloned git@github.com:org/myrepo-new

Your original repo should look like this now:

$ git remote -v

origin  git@github.com:org/myrepo-original (fetch)
origin  git@github.com:org/myrepo-original (push)
cloned  git@github.com:org/myrepo-new (fetch)
cloned  git@github.com: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. =)

leomilrib
  • 409
  • 5
  • 11
2

Github now allows intra-organization forks.

enter image description here

karel
  • 5,489
  • 46
  • 45
  • 50
Sean Kelley
  • 131
  • 5