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?
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?
cd
into "new" repositorygit remote add origin git@github.com: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.
The similar problem I have solved in the way described below.
Assumptions:
Expectations:
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.
Copy the old .git
folder to the new ones.
And then do push flow as usual (git add, commit, push).