Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace one project with another on git repository

Tags:

git

gitlab

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?

like image 940
ParekhAbhishekN Avatar asked Oct 12 '15 19:10

ParekhAbhishekN


2 Answers

  1. Go to your local clone of the new project

  2. Point your remote to the URL of the old repo

  3. Push your branches, using the -f flag to overwrite existing branches. (You'd better be sure you don't need the old ones!)

  4. Delete old branches of the old repo that you no longer need

like image 169
janos Avatar answered Nov 09 '22 07:11

janos


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.

like image 31
Ja Rek Avatar answered Nov 09 '22 06:11

Ja Rek