Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace GitHub repo while preserving issues, wiki, etc

Tags:

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.

What's the best way of doing that without messing up the code nor GitHub?

like image 316
donald Avatar asked Dec 11 '11 02:12

donald


People also ask

Can anyone change my GitHub repo?

No, but if the repository is public others can fork it, commit to their own fork. They can then ask you to pull some of the changes in their fork into your repository via a pull-request. Show activity on this post. Nobody can push directly to your repository if you are not already granting them write access.


2 Answers

  • cd into "new" repository
  • git remote add origin [email protected]: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.

like image 110
Andrew Marshall Avatar answered Sep 22 '22 12:09

Andrew Marshall


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.

like image 29
Suragch Avatar answered Sep 24 '22 12:09

Suragch