Reputation: 23606
How can I fork a public repository, but make my fork private? I do have the subscription to support private repositories.
Upvotes: 574
Views: 327000
Reputation: 2533
The Web UI doesn't allow setting the visibility, but the GitHub CLI can do it. Simply fork the repository and then do
gh repo edit --visibility private <link to your fork>
Your repo will be shortly unavailable because it's "moving to another place", probably for security because normally
As soon as that's done you have a forked, private repo.
Upvotes: 15
Reputation: 9363
I am new to git, so wanted to do as much as possible in the eclipse GUI (v2020-12; EGit v5.11). Details below.
---> The import method in other answers was designed only for Subversion, Mercurial, or TFS projects. It is not supported by GitHub for git projects, as I learned firsthand. It might work, but why risk it?
Repositories and GitHub Connection
eclipse/org.aspectj
is the original public repo and the upstream
remote for fetching
cb4/org.aspectj
is the fork and the origin
remote for pushing
cb4/remPrivAJ
is the remote private repo and the private
remote for pushing
I:\local
is the local repo
For github authentication, I used ssh with an ed25519 key (steps in this SO answer) so my connection URIs look like this: ssh://[email protected]/<user>/<repo>
.
Notation: ->
is a mouse click or selection; right->
is a right click.
STEPS
-> Clone a Git Repository and add clone to this view -> Clone URI -> Next
-> Next
-> Next
-> Finish
to populate the local repoupstream
for pulling down updates
right-> Remotes -> Create Remote ->
and enter name upstream
-> Configure fetch -> Create -> Change ->
enter original repo URI -> Finish
-> Save and Fetch ->
all branches are downloaded -> Close
-> Advanced
under Specifications to fetch
, delete the lone entry thereAdd create/update specification -> Source ref: dropdown
and select master [branch] -> +Add Spec -> Force Update
-> Save specifications in upstream configuration -> Finish -> Save and Fetch ->
only master branch is downloaded -> Close
Like so:
git clone --bare git://github.com/eclipse/org.aspectj.git tmpRepo
<if prompted, enter ssh passphrase>
cd tmpRepo
git push --mirror ssh://[email protected]:cb4/private.git
<if prompted, enter ssh passphrase>
cd ..
rmdir tmpRepo /s /q
private
for pushingright-> Remotes -> Create Remote ->
and enter name private
-> Configure push -> Create -> Change ->
enter remote private repo URI -> Finish
-> Advanced -> Add All Branches Spec -> Force Update -> Save specifications in origin configuration -> Finish
-> Save and Push
master branch is pushed -> Close
At this point, you have forked a public repo into your private repository. To see how to push private changes to your fork and then open a pull request against the original public repo, see my answer here. The resulting configuration looks like this:
Upvotes: 7
Reputation: 1404
Just go to https://github.com/new/import .
In the section "Your old repository's clone URL" paste the repo URL you want and in "Privacy" select Private
.
Upvotes: 83
Reputation: 40924
The answers are correct but don't mention how to sync code between the public repo and the fork.
Here is the full workflow (we've done this before open sourcing React Native):
First, duplicate the repo as others said (details here):
Create a new repo (let's call it private-repo
) via the Github UI. Then:
git clone --bare https://github.com/exampleuser/public-repo.git
cd public-repo.git
git push --mirror https://github.com/yourname/private-repo.git
cd ..
rm -rf public-repo.git
Clone the private repo so you can work on it:
git clone https://github.com/yourname/private-repo.git
cd private-repo
make some changes
git commit
git push origin master
To pull new hotness from the public repo:
cd private-repo
git remote add public https://github.com/exampleuser/public-repo.git
git pull public master # Creates a merge commit
git push origin master
Awesome, your private repo now has the latest code from the public repo plus your changes.
Finally, to create a pull request private repo -> public repo:
Use the GitHub UI to create a fork of the public repo (the small "Fork" button at the top right of the public repo page). Then:
git clone https://github.com/yourname/the-fork.git
cd the-fork
git remote add private_repo_yourname https://github.com/yourname/private-repo.git
git checkout -b pull_request_yourname
git pull private_repo_yourname master
git push origin pull_request_yourname
Now you can create a pull request via the Github UI for public-repo, as described here.
Once project owners review your pull request, they can merge it.
Of course the whole process can be repeated (just leave out the steps where you add remotes).
Upvotes: 826
Reputation: 613
GitHub now has an import option that lets you choose whatever you want your new imported repository public or private
Upvotes: 30
Reputation: 2776
You have to duplicate the repo
You can see this doc (from github)
To create a duplicate of a repository without forking, you need to run a special clone command against the original repository and mirror-push to the new one.
In the following cases, the repository you're trying to push to--like exampleuser/new-repository or exampleuser/mirrored--should already exist on GitHub. See "Creating a new repository" for more information.
Mirroring a repository
To make an exact duplicate, you need to perform both a bare-clone and a mirror-push.
Open up the command line, and type these commands:
$ git clone --bare https://github.com/exampleuser/old-repository.git # Make a bare clone of the repository $ cd old-repository.git $ git push --mirror https://github.com/exampleuser/new-repository.git # Mirror-push to the new repository $ cd .. $ rm -rf old-repository.git # Remove our temporary local repository
If you want to mirror a repository in another location, including getting updates from the original, you can clone a mirror and periodically push the changes.
$ git clone --mirror https://github.com/exampleuser/repository-to-mirror.git # Make a bare mirrored clone of the repository $ cd repository-to-mirror.git $ git remote set-url --push origin https://github.com/exampleuser/mirrored # Set the push location to your mirror
As with a bare clone, a mirrored clone includes all remote branches and tags, but all local references will be overwritten each time you fetch, so it will always be the same as the original repository. Setting the URL for pushes simplifies pushing to your mirror. To update your mirror, fetch updates and push, which could be automated by running a cron job.
$ git fetch -p origin $ git push --mirror
https://help.github.com/articles/duplicating-a-repository
Upvotes: 40
Reputation: 2596
There is one more option now ( January-2015 )
Upvotes: 201
Reputation: 4063
The current answers are a bit out of date so, for clarity:
The short answer is:
This is documented on GitHub: duplicating-a-repository
Upvotes: 52