Skip to content

Instantly share code, notes, and snippets.

@raman-babich
Forked from 0xjac/private_fork.md
Last active October 9, 2019 13:24
Show Gist options
  • Save raman-babich/2f0643889b05b62e254336af1e5897a2 to your computer and use it in GitHub Desktop.
Save raman-babich/2f0643889b05b62e254336af1e5897a2 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 frok 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 [email protected]:raman-babich/public-private-fork-poc.git
  2. Create a new private repository on Github and name it private-private-fork-poc.

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

  3. Mirror-push your bare clone to your new private-private-fork-poc repository.

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

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

    cd ..
    rm -rf public-private-fork-poc.git
  5. You can now clone your private-private-fork-poc repository on your machine (in my case in the code folder).

    cd ~/code
    git clone [email protected]:<your_username>/private-private-fork-poc.git
  6. Add the original repo as remote.

    git remote add upstream [email protected]:raman-babich/public-private-fork-poc.git

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

    origin	[email protected]:<your_username>/private-private-fork-poc.git (fetch)
    origin	[email protected]:<your_username>/private-private-fork-poc.git (push)
    upstream	[email protected]:raman-babich/public-private-fork-poc.git (fetch)
    upstream	[email protected]:raman-babich/public-private-fork-poc.git (push)
    

    Update remotes:

    git remote update

    Create upstream-master branch and configure upstream to upstream/master. Configure upstreams for branches:

    git checkout -b upstream-master upstream/master

    upstream-master will be your local convenient clone of the [email protected]:raman-babich/public-private-fork-poc.git master branch. You can simple git pull and git push to pull or push from [email protected]:raman-babich/public-private-fork-poc.git master branch.

  7. If you have new commits on your public repo and you want to sync up them with private one.

    git checkout upstream-master
    git pull
    git checkout master
    git merge upstream-master

    Or

    git checkout master
    git pull upstream master

    And resolve conflicts if they appear.

  8. If move some commits from your private fork to public repo. (Just cherry pick them)

    git checkout upstream-master
    git pull
    git cherry-pick <masterCommitSha>
    git push

    Resolve conflicts if they appear.

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