Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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 git@github.com:usi-systems/easytrace.git
  2. Create a new private repository on Github and name it easytrace.

    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 easytrace repository.

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

    cd easytrace.git
    git push --mirror git@github.com:<your_username>/easytrace.git
  4. Remove the temporary local repository you created in step 1.

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

    cd ~/code
    git clone git@github.com:<your_username>/easytrace.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 git@github.com:usi-systems/easytrace.git
    git remote set-url --push upstream DISABLE

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

    origin	git@github.com:<your_username>/easytrace.git (fetch)
    origin	git@github.com:<your_username>/easytrace.git (push)
    upstream	git@github.com:usi-systems/easytrace.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

  7. Make your easytrace repo available in your Vagrant VM by adding the following to your Vagrantfile

    Replace "~/code/easytrace" with your local path to the easytrace repo.

    config.vm.synced_folder "~/code/easytrace", "/easytrace"
    
  8. Reload your VM to enable the synced folder (in the folder containing your Vagrant file).

    vagrant reload 
  9. The easytrace repo is available at /easytrace once you ssh into the machine.

@kolosek

This comment has been minimized.

Copy link

@kolosek kolosek commented Nov 24, 2018

Great, thanks!

@aksel

This comment has been minimized.

Copy link

@aksel aksel commented Nov 29, 2018

I've been using this a lot. Thanks!

@paulc4

This comment has been minimized.

Copy link

@paulc4 paulc4 commented Dec 7, 2018

Thanks for this. Pity github made it so unnecessarily complicated.

@ivanrodjr

This comment has been minimized.

Copy link

@ivanrodjr ivanrodjr commented Dec 14, 2018

Amazing, thanks.

@ravicious

This comment has been minimized.

Copy link

@ravicious ravicious commented Aug 14, 2019

Nowadays you should be able to just use the Import a Repository feature. Not sure if you can import someone's repo straight away, but I first did a public fork and then imported that as private.

@rromanchuk

This comment has been minimized.

Copy link

@rromanchuk rromanchuk commented Aug 29, 2019

@ravicious can confirm it works directly

@kamalojasv181

This comment has been minimized.

Copy link

@kamalojasv181 kamalojasv181 commented Dec 2, 2019

When i make a private fork. can i later make pull requests to the original repository?

@georgezim85

This comment has been minimized.

Copy link

@georgezim85 georgezim85 commented Mar 30, 2020

Saved my life. Thank you.

@joeminicucci

This comment has been minimized.

Copy link

@joeminicucci joeminicucci commented May 12, 2020

Nowadays you should be able to just use the Import a Repository feature. Not sure if you can import someone's repo straight away, but I first did a public fork and then imported that as private.

The GUI appears to work great, however the API doesn't outline a way to import the repo as public/private.

@cmcconnell1

This comment has been minimized.

Copy link

@cmcconnell1 cmcconnell1 commented Jun 3, 2020

Thanks for posting this, @joeminicucci (as others have noted using import above), here's how you can import a public repo:
ref: https://help.github.com/en/github/importing-your-projects-to-github/importing-a-repository-with-github-importer

@shailesh-kanzariya

This comment has been minimized.

Copy link

@shailesh-kanzariya shailesh-kanzariya commented Jul 13, 2020

Thank You, this really helped. I followed all steps and I got changes from upstream as well as from origin into current local source code I have after following all steps including git fetch upstream and git rebase upstream/dev. (in my case, it is dev instead of master)
However, after this when I exec git status it tells me :
On branch dev
Your branch and 'origin/dev' have diverged,
and have x and y different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
nothing to commit, working tree clean

Why? What that means? And what is to be required in such case?

@scandri

This comment has been minimized.

Copy link

@scandri scandri commented Aug 10, 2020

Thank you, this was really straightforward to follow.

How would I achieve the same thing for submodules? Do I have to do them all one by one?

@Kenan7

This comment has been minimized.

Copy link

@Kenan7 Kenan7 commented Aug 17, 2020

thank you, this git mirror thing is great.

@shrutikaponde

This comment has been minimized.

Copy link

@shrutikaponde shrutikaponde commented Oct 6, 2020

That went smoothly. Thanks!!!

@kiltannen

This comment has been minimized.

Copy link

@kiltannen kiltannen commented Oct 24, 2020

Nowadays you should be able to just use the Import a Repository feature. Not sure if you can import someone's repo straight away, but I first did a public fork and then imported that as private.

So this just works cleanly and well. THANKS!

@salam16

This comment has been minimized.

Copy link

@salam16 salam16 commented Oct 28, 2020

Thank you so much!!!

@AaganMaskey

This comment has been minimized.

Copy link

@AaganMaskey AaganMaskey commented Oct 31, 2020

Nowadays you should be able to just use the Import a Repository feature. Not sure if you can import someone's repo straight away, but I first did a public fork and then imported that as private.

Thank you, it helped me!

@jaguardo

This comment has been minimized.

Copy link

@jaguardo jaguardo commented Dec 8, 2020

If you use the "import" feature, can you then pull from the public repo and merge it into the private repo fork?

@harsh778

This comment has been minimized.

Copy link

@harsh778 harsh778 commented Dec 15, 2020

Thanks! Helped me big time.

@JanezCim

This comment has been minimized.

Copy link

@JanezCim JanezCim commented Dec 15, 2020

When i make a private fork. can i later make pull requests to the original repository?

Im also interested in this.

@0mars

This comment has been minimized.

Copy link

@0mars 0mars commented Jan 3, 2021

When i make a private fork. can i later make pull requests to the original repository?

Im also interested in this.

I guess the solution is to have your fork public, then private fork your public fork, then make a patch on your public fork

@flieks

This comment has been minimized.

Copy link

@flieks flieks commented Mar 17, 2021

@0mars you mean syncing your public fork (with upstream) and then merge your public fork with your private fork ? Or how do you patch your fork or even merge another repo (public fork into private repo) ?

@JimCownie

This comment has been minimized.

Copy link

@JimCownie JimCownie commented Mar 17, 2021

Minor typo: The correct way of creating a private frok by duplicating the repo is documented here.
frok => fork

@danielkellyio

This comment has been minimized.

Copy link

@danielkellyio danielkellyio commented Mar 19, 2021

very helpful! Thanks!

@MedadRufus

This comment has been minimized.

Copy link

@MedadRufus MedadRufus commented Jul 1, 2021

Nowadays you should be able to just use the Import a Repository feature. Not sure if you can import someone's repo straight away, but I first did a public fork and then imported that as private.

Perfect.

@gartisk

This comment has been minimized.

Copy link

@gartisk gartisk commented Jul 4, 2021

Thanks for the explanation! Before I had noticed the github import repo solution, I made a bash script using your instructions and publish it here

https://github.com/gartisk/pseudo-fork

@nftgeek

This comment has been minimized.

Copy link

@nftgeek nftgeek commented Jul 20, 2021

Thanks

@eugenedw

This comment has been minimized.

Copy link

@eugenedw eugenedw commented Jul 28, 2021

Thank you!

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