'Which set of commands to use to make private fork of public github repo

I'm trying to fork a public github repo but keep the fork private on my end. I've found steps for doing that here: https://gist.github.com/0xjac/85097472043b697ab57ba1b1c7530274 (and other places, but the instructions are similar)

So after doing steps 1 & 2, step 3 is to push the content to the new repo via this command:

git push --mirror [email protected]:<your_username>/<repo_name>.git

Meanwhile, the new github repo shows the standard tips, which include this:

...or push an existing repository from the command line:

git remote add origin [email protected]:<your_username>/<repo_name>.git
git branch -M main
git push -u origin main

What is the difference between these 2 approaches?

  1. git remote add + a normal git push
  2. git push --mirror all by itself

Git remotes & refs kind of make my head spin. In general, I understand approach #1 and am inclined to do that but I'm not sure if it's appropriate here. Approach #2 is the recommendation but I don't understand the description of the mirror option in the man page.

Edit: In retrospect, I totally misunderstood the --bare option from step 1, which would have helped me understand the --mirror option later on. The --bare option says:

Make a bare Git repository. That is, instead of creating <directory> and placing the administrative files in <directory>/.git, make the <directory> itself the $GIT_DIR.

This is not clearly written, IMO. I thought this meant "mix the administrative files in with the working tree", which seemed strange, but now I see it means "only clone administrative files, not the working tree".



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source