Skip to content

Instantly share code, notes, and snippets.

@fordnox
Forked from antomor/clone_and_push.bash
Created September 22, 2022 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fordnox/026ed7a82e9da998f74556e47e3285fa to your computer and use it in GitHub Desktop.
Save fordnox/026ed7a82e9da998f74556e47e3285fa to your computer and use it in GitHub Desktop.
make a private fork of a public repo
# from https://stackoverflow.com/a/30352360/6816965
# 1. clone the publish repo and push it into the private one
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
# 2. work on the private repository as usual
git clone https://github.com/yourname/private-repo.git
cd private-repo
make some changes
git commit
git push origin master
# 3. sync the original repo with the private one
git remote add public https://github.com/exampleuser/public-repo.git
git pull public master # Creates a merge commit
git push origin master
# 4. PR private -> public
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment