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?
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.
cd
into "new" repositorygit remote add origin [email protected]:myusername/myrepository
(replacing myusername
& myrepository
accordingly)git push --force origin master
This will forcefully replace everything in the remote repository with what you have locally. Be very careful, there is no going back.
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
.
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.)
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.
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"
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"
git push
Now your new project will be in GitHub, but the old project's commit history will still be available.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With