12

suppose I have a remote repository (git@server:project.git) with following structure:

./client
./server

And then I created a local repository in directory ~/myproject/test using git init; git add . ; git commit -m "init check in ". I want to push this local repository to the remote repository as a sub-directory testparalleled with client and server , that is

./client
./server
./test

I wish all the check-in history in the local could be kept in the remote repository . Is there any way to achieve this? Thanks!

pierrotlefou
  • 39,805
  • 37
  • 135
  • 175

2 Answers2

7

The usual solution is to use a subtree merge strategy.

See "Git subtree merge strategy, possible without merging history?" for the details.


One other solution would be to declare your local repo as a submodule of your remote repo.

For that, you would need:

  • to push your local repo as an independent repo on your remote server
  • to clone git@server:project.git locally
  • add git@server:test.git as a submodule

But if your test files are closely linked to your project, that is probably not the best solution.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
1

Previous answers did not work for me (needed more details : Git beginner here ;-), whereas https://git-scm.com/book/en/v2/Git-Tools-Submodules did it perfectly with a step-by-step approach. It also explains both methods to merge / discard history.

Surge
  • 103
  • 1
  • 8
Httqm
  • 799
  • 7
  • 13