简体   繁体   中英

Git submodule/subtree gotchas

I have a repository A and I need to provide an access to a specific folder to the other team B.

The scenario is the following. When team A works on the whole A repository the keep working as usual and when they push only the changes made within A\\B folder have to go into repository B.

When B team modify code in B repository, developers in A repository should get it accordingly.

Basically it is one-to-one correspondence. Latest A code and latest B code should always be in sync.

A team modifies code very often. B team modifies code very rarely.

Development process has to be as smooth as possible for B team. Ideally it should be also smooth for A team.

I've considered both submodules and subtrees but lots of articles suggest to get rid of submodules and use only subtrees.

I've started with subtree approach and first of all, in order to keep code in sync, I've written two scripts for A developers to pull and push code from B repository.

git subtree pull B git subtree push B

However push approach did not work well, because B team works very rarely so there is no frequent changes and git subtree is not smart enough with the remembering last synchronized commits and kept rechecking them over and over (the process is done during git subtree split called within git subtree push )

I tried a lot of approaches and ended up scripting making an artificial fake commit within B repository everytime I push A repository. This kinda works but the commit log looks very dirty since then.

Another problem is the fact it's quite difficult to integrate all of this script magic with Pull Request routines, so I had to write scripts to accept Pull Requests which calls my additional logic for the B repository.

For me it all of that looks like I am doing something terribly wrong.

I started to investigate submodules and found they will be also very unfriendly for A developers and Pull Requests.

I am seeking to the Community output how would such an easy problem addressed without such overhead

I would definitely go for submodules in this case. That's exactly what it is made for. Sharing code between projects (repos). However, as you state, it is not that easy to use and understand. Read up on it before you start to use it. Once you feel comfortable with how it works, it'll be quite easy. Good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM