Replace GitHub repo while preserving issues, wiki, etc

后端 未结 3 879
时光取名叫无心
时光取名叫无心 2020-12-09 09:05

I have a repo on GitHub with a lot of issues there. I want to replace the entire code base of that repo with a new one but I want to keep all the previous information.

相关标签:
3条回答
  • 2020-12-09 09:47
    • cd into "new" repository
    • git remote add origin git@github.com:myusername/myrepository (replacing myusername & myrepository accordingly)
    • git push --force origin master
    • Possibly delete other remote branches and push new ones.

    This will forcefully replace everything in the remote repository with what you have locally. Be very careful, there is no going back.

    0 讨论(0)
  • 2020-12-09 09:52

    Since git push --force origin master does not preserve the code commits from the old project, I think this question needs another answer. I already made an answer for an Android Studio project, but it is not much different to use Git exclusively.

    I'll call the old project on GitHub that you want to replace MyProject.

    Backup your new project

    Rename your current project (or copy it to a new location and delete the folder with the original project name. We will clone the old project version from GitHub to this location.)

    Clone the old project from GitHub

    Go to the directory that you want your project in and run

    git clone https://github.com/username/repo.git
    

    Replace username with your GitHub user name and repo with your repository name.

    Remove all the old files

    You can try

    git rm -r *
    

    But if that doesn't work (as it didn't work for me), then manually remove them with rm or a file manager. However, don't delete the .git folder and .gitignore.

    Then if you deleted them manually, you need to update git.

    git add -u
    git commit -m "deleting old files before adding updated project"
    

    Add the new files

    Copy in all the files from your new project that you previously made a backup of. Now let git know that you want to add them to the repository.

    git add .
    git commit -m "new updated project"
    

    Push your changes to GitHub

    git push
    

    Now your new project will be in GitHub, but the old project's commit history will still be available.

    0 讨论(0)
  • 2020-12-09 10:04

    The similar problem I have solved in the way described below.

    Assumptions:

    • "old project" is on GitHub repo
    • "new project" is created localy on your machine

    Expectations:

    • new project must be pushed to the old repo on github
    • old commit history has to remain and be visible in github

    Solution:

    1) go to the "old project" folder on your local machine

    2) find the hidden ".git" folder there and copy it

    3) go to the new project folder on your machine

    4) check if there is a .git folder (it is hidden so you need to show hidden files) - if there is a .git folder rename it, you can either delete it but its better to rename now and delete if all will go according to plan - if there is not .git folder go to the point 5 below. 5) paste previously copied .git folder (from old project) and paste it in the "new project" folder

    Now the new project has a .git folder with all previous changes and history and includes the reference to the URL of you old repo on GitHub.

    6) If you are using for example VS, you can check changes in code. There will be lots of them, or check them in terminal. You can check that old files have been deleted and new files added.

    7)Push actual new project. This new project will be pushed to your old repo on GitHub. Check your git repo on web to be sure that all went well.

    8) Now you can delete old project from your local machine and delete this renamed new git hidden folder (it was renamed in point 4).

    Now you can develop your new project, keeping all old history with you.

    Hope it helps.

    0 讨论(0)
提交回复
热议问题