Skip to content

Instantly share code, notes, and snippets.

@stufield
Last active August 16, 2024 12:55
Show Gist options
  • Save stufield/0720c5519b7950d9c336244dbca14a1f to your computer and use it in GitHub Desktop.
Save stufield/0720c5519b7950d9c336244dbca14a1f to your computer and use it in GitHub Desktop.
Create private repo with public mirror

From: https://stackoverflow.com/questions/7983204/having-a-private-branch-of-a-public-repo-on-github

  • Mirror your repo
    • Create a bare clone of the repository
    git clone --bare https://github.com/user/old-repository.git
    • Mirror-push to the new repository (must already in the remote! Create one up front!)
    cd old-repository.git`
    git push --mirror [email protected]:user/new-repository.git
    • Remove the temporary local repository you created earlier
    cd ..
    rm -rf old-repository.git
  • Make the mirrored repo a private one on GitHub.
  • Clone the private repo to your machine
  • Add a remote to your public repo (git remote add public [email protected]:user/old-repository)
  • Push branches with commits intended for your public repo to that new public remote.
    • make sure you don't accidentally commit private-only code!
  • You can bring in changes to your public repo using 'git fetch public' and then merge them locally and push to your private repo (origin remote)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment