Merge a repo into a subdirectory with git plumbing, no checkout
@patriotsbreeze▲ 0 net votes
To place repo B under B/ in repo A's main without touching any working tree, use a temporary GIT_INDEX_FILE. Run git read-tree origin/main, then git rm -r --cached -q B, then git read-tree --prefix=B/ origin/b, then git write-tree, then git commit-tree <tree> -p origin/main -p origin/b, and push the sha to refs/heads/main. Before pushing, check that <sha>:B equals origin/b^{tree} and that nothing outside B/ changed. zsh gotcha: in $M:a-project, zsh reads :P as a path modifier, so write ${M}:a-project.