0

My project consists of two folders, each with its own repository:

project/
|--frontend/
|--|--.git
|--backend/
|--|--.git

So far I have worked on them locally. Now I want to create one global repository for my project to push it into remote while saving both histories in it. What is the right way to do it?

project/
|--.git - has entire history of project (both folders)
|--frontend/
|--|--.git - can be deleted if method requires it
|--backend/
|--|--.git - can be deleted if method requires it
ti7
  • 16,375
  • 6
  • 40
  • 68
Arctomachine
  • 401
  • 6
  • 12

1 Answers1

0

I suspect you can do this by moving the path of each and merging one into the other

This assumes it's desirable to add the frontend into the backend repository, though this might not be the case for you - repeat the steps for each if creating a new repository

WARNING I HAVE NOT TESTED THIS YET

Make a backup of your repositories

cp -r project project.bak  # FIXME targz

Check out a custom branch (in backend)

(frontend)% git checkout -b custom-move-frontend
(backend)% git checkout -b custom-move-backend

update the remote so they are part of the same repository

get the remote from each

(frontend)% git remote -v  # display remote URL
(backend)% git remote -v

update the backend's remote

(backend)% git remote set-url origin "$FRONTEND_REMOTE"

Move the contents of each into its future name

(frontend)% git mv . ./frontend
(frontend)% git add .
(frontend)% git commit -m "MY UPDATE TEXT FRONTEND"
(frontend)% git push  # original URL

(backend)% git mv . ./backend
(backend)% git add .
(backend)% git commit -m "MY UPDATE TEXT BACKEND"
(backend)% git push  # branch is pushed to frontend's URL

join the unrelated histories

The branches do not share a common history

Git refusing to merge unrelated histories on rebase

(frontend)% git pull
(frontend)% git checkout -b custom-merge-merge  # from custom-move-frontend
(frontend)% git merge --allow-unrelated-histories origin/custom-move-backend

the repositories are now merged


extras

I highly recommend adding a file with notes about what happened and at what specific commits

prefixing your commits with a unique string may help you find them later

ti7
  • 16,375
  • 6
  • 40
  • 68