We have an internal corporate github repository that we want to open-source to github.com soon. In order to do so safely we want to remove the git history upon the initial push to the public repo. Therefore we need to:
As an example, if the local history at the time of the initial public push is:
A -> B -> C -> D
then the public repo after the initial push should look like:
D
After adding two new commits, E and F, the two repos should looks like this respectively:
Local:
A -> B -> C -> D -> E -> F
Public:
D -> E -> F
How can we achieve all of that simultaneously as easily as possible? I realize that there are lots of questions/answers regarding truncating history or having more than one remote, but I haven't found anything about both of those features simultaneously.
One solution is to create a initial commit for your public repo, and use git replace --graft to sort of bind your internal and public histories together. I have personally found this solution to be great in a similar situation as you described in your question. In this case the histories will look like this:
History in your internal Github repo:
A -> B -> C -> D -> I (replaced) -> E -> F
History in your public Github repo:
I -> E -> F
where commits E and F are new development and I is the initial commit for public repo.
Steps to achieve this (assuming master is the main branch in all repos):
DI for you public repoD and Igit replace --graft hash_of_commit_I hash_of_commit_Dgit show-ref you'll see ref refs/replace/*git log will show replaced mark on commit II to master)git push internal_remote 'refs/replace/*'git push internal_remote HEAD:mastergit push public_remote master, there should only be the initial commit I and no previous historygit commitgit push internal_remote mastergit push public_remote masterIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With