Reputation: 11
I'm working on a service that uses github. For a function, I need to force push everything from Repo 1 to Repo 2.
*Don't care about any of the content, trees, commit history, etc of Repo 2. It is to be replaced.
End goal is that Repo 2 ends up identical to Repo 1. Same contents, commit history, etc.
I'm auth-ed for both accounts so that isn't an issue.
Looking at the available endpoints I'm a bit confused as to how to do this from a high level.
I think it would be pulling the entire tree and all blobs from Repo 1, and setting Repo 2 to be equal to that using update-refs? I'm not sure how best to tackle this.
So far I have been able to successfully pull all files from Repo 1, create a commit, and push it to Repo 2 using the API. However I'm not sure how to 'force push' and make Repo 2 have the same history/contents/etc. as Repo 1.
Upvotes: 1
Views: 286
Reputation: 76784
You can't use the GitHub API for this, since the GitHub API doesn't provide a way to work with large amounts of Git data or transfer Git data from one repo to another.
You'll need to clone the original repository with git clone --mirror
, delete any refs under refs/pull
, and then push to the new repository. Using Git is the simplest and easiest way to solve this problem, and the only way to produce an identical history.
Upvotes: 0