Transferring branches between two different repos with (near) identical content but different commits

Background:

I have a system that is air gapped from our primary development machines. I am developing software on the networked machines, and then updates from the primary git repository must be manually patched to the repository maintained on the other system. We do this by applying just the diff for each patch to the air gapped system each time, rather than recreating the entire repository every time. There is a need for a repository to be maintained on the air gapped system as well, as there are development branches specific to that machine also.

For the most part this serves my purposes, but there is potential for human error at several places along the patching process and this has occurred in the past. I wish to patch the entirety of the repository again to eliminate issues with portions of diffs that have failed to be applied in the past.

The problem:

How could I transfer branches that are specific to the air gapped system from the old repository to the new one? The repositories are extremely similar in content (not identical – probably 98% of files are identical but 2% would contain differences) but have entirely different commit histories. Changing origin for example will just complain there are no commits in common.

The branch history is not particularly important, if I was able to reapply just the changes, so perhaps just doing that would be sufficient, but I am not sure what options are in this situation.

2

git bundle is the easy way to sneakernet history across an air gap. Bundle up your histories, put them on a thumb drive and walk it across, fetch from the bundle, Git will notice and skip any full dups and eventually squeeze out any partial-content repetitions as usual.

If data size is a concern, if the bundle is painfully large, you can get intrusive with your checking, git bundle is just a convenience command managing a(n arbitrary but handy) single-file way of packaging refs and objects, you can pack them up yourself, especially for one-time use like this seeing how it works can even be helpful.

To do a full duplicate-object-elimination before packing you need a list of objects already at the destination, so

  1. Get a list of objects already on your airgapped system: in your airgapped repo,
git cat-file --batch-all-objects --batch-check='%(objectname)' 
        > /path/to/thumbdrive/objects-at-destination

  1. pack up only what’s new on your source system: in your source repo there, with that thumbdrive mounted,
branches="shipbranch1 shipbranch2 etc"
git rev-list --objects --no-object-names $branches | sort 
| join -v1 - /path/to/thumbdrive/objects-at-destination 
| git pack-objects /path/to/thumbdrive/pack
git for-each-ref --format='create %(refname) %(objectname)' 
       $(git rev-parse --symbolic-full-name $branches) 
       > /path/to/thumbdrive/new-tips
  1. Bring in the new history: on your airgapped system, in the repo there:
cp /path/to/thumbdrive/pack-* .git/objects/pack   # or objects/pack if the repo's bare
git update-ref --stdin </path/to/thumbdrive/new-tips
  1. If the added packs are annoyingly large you can do a full reconsider-my-life-choices-while-I-wait-for-this repack:
git repack -adf --window 500 --window-memory 1G

which with any history large enough to actually need it will take a very long time on a weak system (and a good few minutes on even a sort-of-decent one) but will also likely save a lot of space. If you’ve already done it once you can leave off the f flag to save much time and get almost all the available benefit.

I’ve smoketested this (and done similar things irl) so it’s at least close to right.

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