Home > Back-end >  How to completely replace remote repository git history with local copy?
How to completely replace remote repository git history with local copy?

Time:05-17

I have a repository in GitHub and a local repository. I want to completely overwrite GitHub repository with local repository, overwrite everything - commit history, files, everything. These 2 repositories are not related - they are different from each other.

I need it because I made a mistake - I merged 2 unrelated repositories, in the result I have in one repo mix of both, but I have another local folder with no such mistake.

CodePudding user response:

  1. Delete the GitHub repository and make a new one. It can have the same name if you like. Make sure it is totally empty (do NOT make a ReadMe or anything like that).

  2. Set that new GitHub repo as the remote of your local repo (GitHub tells you how to do that when you create the repo).

  3. On your local machine, push every branch (you might, depending on your settings, be able to simplify with git push --all, but if not you will just have to push each branch individually).

CodePudding user response:

If it doesn't need to be the exact same Github repository, you might be able to follow the steps detailed here: https://docs.github.com/en/get-started/importing-your-projects-to-github/importing-source-code-to-github/adding-locally-hosted-code-to-github I am not entirely sure, but you might be able to also push to an existing repository as well with this method.

  •  Tags:  
  • git
  • Related