I created a git repository for one project, then I created a different project for some reason and now I need to replace the project in the repository with the new one. How do I do that?
Go to your local clone of the new project
Point your remote to the URL of the old repo
Push your branches, using the -f
flag to overwrite existing branches. (You'd better be sure you don't need the old ones!)
Delete old branches of the old repo that you no longer need
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.
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