Recently wanted to clone this repository which is public so that I could store my private configurations while maintaining upstream. Github does not allow the creation of private forks for public repositories.
The correct way of creating a private fork by duplicating the repo is documented here.
Here are my notes for this task:
- Create a bare clone of the repository.
(This is temporary and will be removed so just do it wherever.)
git clone --bare [email protected]:eduardoboucas/staticman.git
-
Create a new private repository on Github and name it
staticman
. - Mirror-push your bare clone to your new
staticman
repository.Replace
<your_username>
with your actual Github username in the url below.cd staticman.git git push --mirror [email protected]:<your_username>/staticman.git
- Remove the temporary local repository you created in step 1.
cd .. rm -rf staticman.git
- You can now clone your
staticman
repository on your machine (in my case in theapis
folder).cd ~/apis git clone [email protected]:<your_username>/staticman.git
- 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 [email protected]:eduardoboucas/staticman.git git remote set-url --push upstream DISABLE
You can list all your remotes with
git remote -v
. You should see:origin [email protected]:<your_username>/staticman.git (fetch) origin [email protected]:<your_username>/staticman.git (push) upstream [email protected]:eduardoboucas/staticman.git (fetch) upstream DISABLE (push)
When you push, do so on
origin
withgit 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