Question

I have a git repository A with contents:

 <shared files dir>/
        sharedFile1
        sharedFile2

And I have additional git repository B with 2 projects, each of them has to use the shared files from repository A. So that the file structure will be similar to this:

Project_X
   <shared files dir>/
      sharedFile1
      sharedFile2
   <project X dirs>

Project_Y
   <shared files dir>/
      sharedFile1
      sharedFile2
   <project Y dirs>

I would like the shared files to be updated only in the repository A, and I need to allow project_X and Project_Y to get those updates easily.

Actually, symbolic link could be the exact solution I need, but unfortunately, the filesystem I use doesn't support it.

Git subtree also looks as suitable solution, but the problem is that I couldn't find how to merge a subtree from same branch to 2 locations in same repository. I succeeded to create the file structure I need:

git read-tree --prefix=Project_X/shared_files_dir/ -u shared_remote_branch
git read-tree --prefix=Project_Y/shared_files_dir/ -u shared_remote_branch

Creates the required filestructure (exactly as I described at the top of the question), but trying to merge updates brings me the changes only to the last subtree I created:

git merge --squash -s subtree --no-commit shared_remote_branch

Updates only the Project_Y/shared_files_dir/, and not the Project_X/shared_files_dir/ with the changes from shared_remote_branch.

I would appreciate any ideas. On how to merge the subtree from one branch to 2 locations (Project_X/shared_files_dir/) and (Project_Y/shared_files_dir/) or how to make it in any other methodology

Was it helpful?

Solution

Since git1.8.2, you can register a submodule as following the latest commits of a given branch.

So I would recommend that approach over the subtree one, as it allows to:

  • maintain a separate history for the shared_files repo
  • easily update to the last commit of a branch

    git submodule update --remote
    

You can even convert an existing submodule in order to have it trakc the latest of a branch.


The OP chose a simpler solution:

I've decided to use a workaround:

  • manage the shared modules in separate repo and
  • add a post-checkout hook to my main repo which will copy those shared files from a shared repo to the main repo.

We are a small team, so this approach is the easiest for us

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top