I forked a public github repository into a private github repository and cloned the code to several servers.
Today I accidentally pulled on one of the servers the new changes from the public fork and not from the private one. I did not notice my mistake right away and merged and pushed this polluted version to the private repository on github. How can I remove all the commits from the original origin, that are now polluting our branch.
I read around on SO and would
- rename the used branch on one of the other servers, that is unchanged. (
git branch -m 'clean'
) - delete the old branch on github and the local server (
git push private_repo --delete <old_branch>
andgit branch -D <old_branch>
) - rename the local branch back (
git branch -m <old_branch>
_) - push the clean version to github (
git push private_repo <old_branch>
) - create patches from the commits, that I created on the server, where I did the wrong pull
- remove the local branch (
git branch -D <old_branch>
) and pull the cleaned branch from the private repo (git pull private_repo <old_branch>
)
Is this the right way? Is there a less complicated and safer way?
[update]
I just stumbled upon https://stackoverflow.com/a/448929/380038
Can I just do:
git push -f private_repo <old_branch>
from one of the unpolluted clones
and than 5. and 6.?
They write in the answer, that push force does not delete commits, but just moves a pointer. Could this create issues, when I want to later pull commits from the original public github repo?