Skip to content

Instantly share code, notes, and snippets.

@dfsmania
Forked from 0xjac/private_fork.md
Last active October 4, 2021 19:48
Show Gist options
  • Save dfsmania/06644703edccafd0e6011451666f5d9b to your computer and use it in GitHub Desktop.
Save dfsmania/06644703edccafd0e6011451666f5d9b to your computer and use it in GitHub Desktop.
Create a private fork of a public repository

The repository for the assignment is public and Github does not allow the creation of private forks for public repositories.

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

For this assignment the commands are:

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

    git clone --bare https://github.com/<user-name>/<repo-name>.git
  2. Create a new private repository on Github and name it <repo-name>.

    If you are unable to create a private repo, you can request unlimited private repos as a studant by getting the student pack from Github.

  3. Mirror-push your bare clone to your new <repo-name> repository.

    Replace <your-username> with your actual Github username in the url below.

    cd <repo-name>.git
    git push --mirror https://github.com/<your-username>/<repo-name>.git
  4. Remove the temporary local repository you created in step 1.

    cd ..
    rm -rf <repo-name>.git
  5. You can now clone your <repo-name> repository on your machine (in my case in the code folder).

    cd ~/code
    git clone https://github.com/<your-username>/<repo-name>.git
  6. If you want, you may 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 https://github.com/<user-name>/<repoy-name>.git
    git remote set-url --push upstream DISABLE

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

    origin	https://github.com/<your-username>/<repo-name>.git (fetch)
    origin	https://github.com/<your-username>/<repo-name>.git (push)
    upstream	https://github.com/<user-name>/<repo-name>.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