Github prohibits making a private repository from a forked repository. This article explains how to create a private repository that can incorporate updates from a public repository, mimicking the behavior of a forked repository.

Bare Clone and Mirror Push

Duplicate public to private repository

  1. Create empty private repo
  2. Bare clone a public repo, and mirror push it to the private repo.
    $ git clone --bare https://github.com/exampleuser/public_repo.git
    $ cd public_repo.git
    $ git push --mirror git@github.com:user-name/repo-name.git
    $ cd ..
    $ rm -rf public-repo.git
    

Register remote repository with public repository

$ git clone https://github.com/yourname/private_repo.git
$ cd private_repo
$ git remote add public https://github.com/exampleuser/public_repo.git

Fetching from public repo

$ git pull public master 
$ git push origin master

References

  1. 0xjac/private_fork.md
  2. https://stackoverflow.com/questions/10065526/github-how-to-make-a-fork-of-public-repository-private

Leave a comment