Skip to content

Instantly share code, notes, and snippets.

@zewebdev1337
Forked from 0xjac/private_fork.md
Last active July 10, 2024 17:42
Show Gist options
  • Save zewebdev1337/c9475488ced77f6786b6f4ebf4312256 to your computer and use it in GitHub Desktop.
Save zewebdev1337/c9475488ced77f6786b6f4ebf4312256 to your computer and use it in GitHub Desktop.
Create a private fork of a public repository

Github does not allow the creation of private forks for public repositories.

The correct way of creating a private frok by duplicating the repo is documented here.

  1. Create a bare clone of the repository. (This is temporary and will be removed so just do it wherever.)

    git clone --bare [email protected]:<original_username>/<original_repo>.git
  2. Create a new private repository on Github.

  3. Mirror-push your bare clone to your new repository.

    cd <original_repo>.git
    git push --mirror [email protected]:<your_username>/<your_repo>.git
  4. Remove the temporary local repository you created in step 1.

    cd ..
    rm -rf <original_repo>.git
  5. You can now clone your repository on your machine.

    git clone [email protected]:<your_username>/<your_repo>.git
  6. If you want, add the original repo as remote to fetch (potential) future changes. Make sure you also disable push on the remote (as you are not allowed to push to it anyway).

    git remote add upstream [email protected]:<original_username>/<original_repo>.git
    git remote set-url --push upstream DISABLE

    You can list all your remotes with git remote -v. You should see:

    origin	[email protected]:<your_username>/<your_repo>.git (fetch)
    origin	[email protected]:<your_username>/<your_repo>.git (push)
    upstream	[email protected]:<original_username>/<original_repo>.git (fetch)
    upstream	DISABLE (push)
    

    When you push, do so on origin with git push origin.

    When you want to pull changes from upstream you can just fetch the remote and rebase on top of your work.

      git fetch upstream
      git rebase upstream/master

    And solve the conflicts if any

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment