Skip to content

Instantly share code, notes, and snippets.

@0xjac
Last active October 8, 2024 22:20
Show Gist options
  • Save 0xjac/85097472043b697ab57ba1b1c7530274 to your computer and use it in GitHub Desktop.
Save 0xjac/85097472043b697ab57ba1b1c7530274 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 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.

@Ozer0x777
Copy link

Petit filou !

@ofey404
Copy link

ofey404 commented Jun 27, 2023

Great job bro!

@kevherro
Copy link

kevherro commented Aug 1, 2023

Thank you!

@sjohnson-FLL
Copy link

Really helpful, spent hours looking for this exact guide!

@Liuhaai
Copy link

Liuhaai commented Aug 23, 2023

👍

@keriksson-rosenqvist
Copy link

Great tutorial.
Follow up question though. How would I go about making a pull request from my private form to the upstream? Normally when you form there's a button in GitHub to allow you to do this but since this is done manually the GitHub linking isn't there. 🤔

@benjaminorr
Copy link

Thank you

@thomasXwang
Copy link

Thanks 😃

@T0psecurity
Copy link

Thx :)

@DLohn
Copy link

DLohn commented Oct 4, 2023

According to this entry on the GitHub Docs, using GitHub's forking method means that you lose access to your fork if the source repo goes private and you are not authorized to view the now private repo. Making a private fork with this method seems like a no-brainer if you don't use backups and want to access your changes.

@ConfoundingVariables
Copy link

This is immensely useful thanks a lot!!

@ConfoundingVariables
Copy link

This is immensely useful thanks a lot!!

https://github.com/new/import also works! 😅

@maxholloway
Copy link

This is a game changer, thank you so much!

@marcusreaiche
Copy link

Great tutorial! Thanks a lot!

@marcasmed
Copy link

Thanks mate!

@novazur972
Copy link

Thanks too !

@carlos-granados
Copy link

Use this one: https://github.com/new/import

This is the easiest option by far. Just enter the URL of the Github repo you want to replicate and that's it

@MejanH
Copy link

MejanH commented Jan 21, 2024

Use this one: https://github.com/new/import

This is the easiest option by far. Just enter the URL of the Github repo you want to replicate and that's it

Thanks man. the best solution.

@fromSmolsoft
Copy link

fromSmolsoft commented Feb 4, 2024

According to this entry on the GitHub Docs, using GitHub's forking method means that you lose access to your fork if the source repo goes private and you are not authorized to view the now private repo. Making a private fork with this method seems like a no-brainer if you don't use backups and want to access your changes.

I suggest to read that entry again specifically this part here: Changing a public repository to a private repository

...a public repository's forks will remain public in their own separate repository network even after the upstream repository is made private...

@sakibdev
Copy link

Best Github guide I found so far. Straight to the point!

@VictorSCamargo
Copy link

be careful that sometimes, when you make this bare clone, github will loose track of what branch is the default, so you have to configurate it

@wmyers
Copy link

wmyers commented Mar 11, 2024

Use this one: https://github.com/new/import

This is the easiest option by far. Just enter the URL of the Github repo you want to replicate and that's it

Thanks man. the best solution.

Yup this works for me

@krulci
Copy link

krulci commented Apr 16, 2024

For people using Visual Studio 2022:

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

For this assignment the commands are:

  1. Create a public fork of the repository easytrace.
    (This is temporary and will be removed.)

  2. Clone your fork using Visual Studio 2022's Clone a repository feature.

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

    git@github.com:<your_username>/easytrace.git
  3. Delete your public fork you made in step 1.

  4. 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.

  5. In Visual Studio 2022, open Git.

    Git > Open in Command Prompt

  6. Mirror-push your bare clone to your new easytrace repository in the command prompt you just opened in step 5.

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

    git push --mirror git@github.com:<your_username>/easytrace.git

@chibexme
Copy link

Use this one: https://github.com/new/import

this one would not work if you want to use the original repo as the upstream where you can be pulling changes to rebase your repo.

@Rain-eslite
Copy link

Thank you!!

@liushuya7
Copy link

Use this one: https://github.com/new/import

Awesome! Thanks!

@laurentshrink
Copy link

I’m having trouble with creating a private fork of a public repo on GitHub. I followed the steps, but I’m unsure about setting up the remote configurations. Can someone clarify the correct process for this?

@d270rg
Copy link

d270rg commented Sep 22, 2024

Thanks

@paullok999
Copy link

Thanks for the tutorial!

@GoudronViande24
Copy link

GoudronViande24 commented Oct 2, 2024

frok

fork*

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