git subtree – merge the whole subrepository with multiple subfolders into the main repository

I have read and used git subtree functionality a lot.
Especially are useful these links
Add subdirectory of remote repo with git-subtree

If I have main repo:

base/folder1
base/folder2

And I have sub repo (repo2):

base/folder3
base/folder4

I cant change the structure of the folders, as this is inherit from some other SCM platform, and build process expects this folder structure.

How I can use git-subtree to have both of the subfolders (folder3 and folder4) inside my main repo and in the same time to track changes from a subrepo? (that is where git subtree should come into place)

I couldn’t find way for this.

Ideally with sub-tree I would like to accomplish a repo with this structure:

base/folder1
base/folder2
base/folder3
base/folder4

I have tried with:

$ git subtree add --prefix . repo2 master --squash
prefix '.' already exists.
$ git subtree add --prefix base repo2 master --squash
prefix 'base' already exists.

If I add into some other folder like “repo2”

  $ git subtree add --prefix repo2 repo2 master --squash

Then this would work but then I would have structure:

base/folder1
base/folder2
base/repo2/folder3
base/repo2/folder4

which is NOT what I want.

Is this possible to achieve with git and subtree functionality?

Thank you

7

I don’t know any simple way to do what you want. Git doesn’t really allow working with separate subdirectories. The entity is the entire repository, the unit of work is a commit which includes a copy of the entire working tree. git subtree allows to export/import subdirectories but you need intermediate repositories to store them.

You can export subfolders from repo2 but you cannot do that in one step — git subtree allows only one prefix. So you need to create two empty intermediate repositories. Let’s say their hosting is at <URL>; lets name these new repos r2f3 and r2f4 to remember their content came from repo2 folder3 and f…4 (if <URL> is actually local filesystem or SSH-accessed filesystem the new repos must be bare because you will push into them; repos at Git hostings are always bare).

First you export subfolders from repo2 into these new repositories:

$ cd repo2
$ git subtree push -P base/folder3 <URL>:r2f3
$ git subtree push -P base/folder4 <URL>:r2f4

The very repo2 stays unchanged except for two new branches, the result of git subtree split ran by git subtree push.

Now import them into repo1:

$ cd repo1
$ git subtree add -P base/folder3 <URL>:r2f3
$ git subtree add -P base/folder4 <URL>:r2f4

When you have new commits in repo2 you do re-export and re-import:

$ cd repo2
$ git subtree push -P base/folder3 <URL>:r2f3

$ cd repo1
$ git subtree pull -P base/folder3 <URL>:r2f3

When you have new commits in repo1 that touch folder3 or 4 you do re-export and re-import in the reverse direction:

$ cd repo1
$ git subtree push -P base/folder4 <URL>:r2f4

$ cd repo2
$ git subtree pull -P base/folder4 <URL>:r2f4

Cumbersome, yes. But works and could be automated with scripts.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật