Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add a local repository as a sub directory of remote repository

Tags:

git

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!

like image 289
pierrotlefou Avatar asked Dec 14 '11 07:12

pierrotlefou


People also ask

Can remote repository be local file system?

Simply put, a remote repository is one that is not your own. It can be another Git repository that's on your company's network, the internet, or even your local filesystem, but the point is that it's a repository distinct from your my-git-repo project.


2 Answers

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.

like image 171
VonC Avatar answered Oct 23 '22 03:10

VonC


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.

like image 1
Httqm Avatar answered Oct 23 '22 02:10

Httqm