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.

@harsh778
Copy link

harsh778 commented Dec 15, 2020

Thanks! Helped me big time.

@JanezCim
Copy link

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
Copy link

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
Copy link

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
Copy link

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
Copy link

danielkellyio commented Mar 19, 2021

very helpful! Thanks!

@MedadRufus
Copy link

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
Copy link

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
Copy link

nftgeek commented Jul 20, 2021

Thanks

@eugenedw
Copy link

eugenedw commented Jul 28, 2021

Thank you!

@yx-chan131
Copy link

yx-chan131 commented Aug 19, 2021

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

I tried with my own personal project, yes you can still pull from the public repo. What I did was after I import the repo, I used these two commands:

git remote add upstream git@github.com:usi-systems/easytrace.git
git remote set-url --push upstream DISABLE

@barryperez
Copy link

barryperez commented Sep 6, 2021

Thanks - just found this gist very useful!

@nkrsic
Copy link

nkrsic commented Sep 22, 2021

Cheers!

@hieu-van
Copy link

hieu-van commented Oct 18, 2021

Nice

@apimaker001
Copy link

apimaker001 commented Dec 23, 2021

Great!

@Vitaly-A-Ivanov
Copy link

Vitaly-A-Ivanov commented Jan 23, 2022

Well written. Thanks

@erdoukki
Copy link

erdoukki commented Feb 9, 2022

Thanks...
Useful!

@GersomR-afk
Copy link

GersomR-afk commented Feb 18, 2022

Even though I do not use this repo, the process of making a private fork helped a lot, thank you!

@ahbanavi
Copy link

ahbanavi commented Feb 19, 2022

Thx a lot.

@vmendivil
Copy link

vmendivil commented Mar 4, 2022

Thank you!

@pat-richter
Copy link

pat-richter commented Mar 10, 2022

Thank you. Step 6 should contain cd easytrace ;-)

@ZekiJohn
Copy link

ZekiJohn commented Mar 17, 2022

Thank you. very helpful 💡💡

@monsefoster
Copy link

monsefoster commented Mar 19, 2022

Thank you!

@hapylestat
Copy link

hapylestat commented Apr 17, 2022

the one thing - it is not forking but duplicating, it means - you wouldn't be able to create a pull request

@AdrienWehrle
Copy link

AdrienWehrle commented Jun 10, 2022

Very useful, thank you a lot! 👍

@PabloC
Copy link

PabloC commented Aug 18, 2022

Thank you, this is great!

@nestvor
Copy link

nestvor commented Sep 23, 2022

Very nice, thank you!

@stefanomorni
Copy link

stefanomorni commented Nov 16, 2022

Thank you very much for this useful guide.
Is it possible to make a pull request to the remote public repo from your private fork/mirror?
If so, how would you do it?
Thank you
Best regards
Stefano

@alexanderkomarovincode3

It's a useful guide. But it's not up to date for this case: "Mirroring a repository that contains Git Large File Storage objects"
Better to check the GitHub Documentation.

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