Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save savareyhano/47d8678c0802a7f1cc0c36314b0d5a41 to your computer and use it in GitHub Desktop.
Save savareyhano/47d8678c0802a7f1cc0c36314b0d5a41 to your computer and use it in GitHub Desktop.

First, duplicate the repo (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).

@savareyhano
Copy link
Author

This gist is derived from an answer provided by Martin Konicek on Stack Overflow. The original answer can be found here

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