{"id":4847,"date":"2015-09-30T09:40:27","date_gmt":"2015-09-30T13:40:27","guid":{"rendered":"http:\/\/www.dr-chuck.com\/csev-blog\/?p=4847"},"modified":"2015-09-30T09:57:10","modified_gmt":"2015-09-30T13:57:10","slug":"using-git-subtrees-in-tsugi","status":"publish","type":"post","link":"https:\/\/www.dr-chuck.com\/csev-blog\/2015\/09\/using-git-subtrees-in-tsugi\/","title":{"rendered":"Using git subtrees in Tsugi"},"content":{"rendered":"<p>I am starting to build PHP and Java implementations of my <a href=\"http:\/\/www.tsugi.org\" target=\"_blank\">Tsugi<\/a> libraries and I want to share the static content (JavaScript, CSS, etc) between them all so they all are effectively testing the same core code as much as possible and I don&#8217;t want to change things two places.  Here are my repos:<\/p>\n<ul>\n<li>Static content: <a href=\"https:\/\/github.com\/csev\/tsugi-static\" target=\"_blank\">https:\/\/github.com\/csev\/tsugi-static<\/a><\/li>\n<li>Application: <a href=\"https:\/\/github.com\/csev\/tsugi-static\" target=\"_blank\">https:\/\/github.com\/csev\/tsugi<\/a> &#8211; the tsugi-static repo is in the folder &#8220;static&#8221;<\/li>\n<\/ul>\n<p>I toyed with submodules &#8211; but adding &#8220;&#8211;recursive&#8221; to all &#8220;git clones&#8221; seemes icky and it seemed ike &#8220;git pull&#8221; in the world of submodules was clunky &#8211; I did not even bother to figure it out before I gave up on submodules.<\/p>\n<p><strong>Goodbye git submodules hello git subtrees.<br \/>\n<\/strong><br \/>\nI read these blog posts to learn up:<\/p>\n<ul>\n<li><a href=\"https:\/\/medium.com\/medium-eng\/how-we-modularized-mediums-ios-codebase-8f8f26965c76\" target=\"_blank\">https:\/\/medium.com\/medium-eng\/how-we-modularized-mediums-ios-codebase-8f8f26965c76<\/a><\/li>\n<li><a href=\"https:\/\/medium.com\/@v\/git-subtrees-a-tutorial-6ff568381844\" target=\"_blank\">https:\/\/medium.com\/@v\/git-subtrees-a-tutorial-6ff568381844<br \/>\n<\/a><\/li>\n<\/ul>\n<p>Conviently in the modern version of git &#8211; it knows how to <a href=\"http:\/\/stackoverflow.com\/questions\/1260748\/how-do-i-remove-a-git-submodule\" target=\"_blank\">blast submodules<\/a> so undoing my use of sub modules was a simple matter of:<\/p>\n<p><code>git rm static<br \/>\ngit push<\/code><\/p>\n<p>Of course my repo was broken at this point so I quickly needed to add the static folder back as a subtree in with these commands.  Note that I did not do the &#8220;remote-add&#8221; and just put hte full URL if the repo in place of the remote on the subtree commands.  I will add the remote if I start pushing from tsugi to tsugi-static.<\/p>\n<pre>\r\n$ git subtree add --prefix=static\/ https:\/\/github.com\/csev\/tsugi-static master\r\ngit fetch tsugi-static master\r\nwarning: no common commits\r\nremote: Counting objects: 159, done.\r\nremote: Compressing objects: 100% (9\/9), done.\r\nremote: Total 159 (delta 3), reused 0 (delta 0), pack-reused 150\r\nReceiving objects: 100% (159\/159), 1.14 MiB | 0 bytes\/s, done.\r\nResolving deltas: 100% (31\/31), done.\r\nFrom https:\/\/github.com\/csev\/tsugi-static\r\n * branch            master     -> FETCH_HEAD\r\n * [new branch]      master     -> tsugi-static\/master\r\nAdded dir 'static'\r\n\r\n$ git push\r\nCounting objects: 160, done.\r\nDelta compression using up to 8 threads.\r\nCompressing objects: 100% (125\/125), done.\r\nWriting objects: 100% (160\/160), 1.20 MiB | 0 bytes\/s, done.\r\nTotal 160 (delta 32), reused 149 (delta 30)\r\nTo https:\/\/github.com\/csev\/tsugi.git\r\n   55ec2c7..87c5f1d  master -> master\r\n0587388153:tsugi csev$ git status\r\nOn branch master\r\nYour branch is up-to-date with 'origin\/master'.\r\n<\/pre>\n<p>Just to be sure I putched my clone and re-cloned tsugi and poof! My static content was there in a folder just like I like it &#8211; no &#8211;recursive required.  <\/p>\n<p><strong>On to the git pull when the subtree repo is updated..<br \/>\n<\/strong><br \/>\nIn general I will make changes in a separately checked out version of tsugi-static, push them up there and then do a pull into tsugi using these commands.  It is a merge &#8211; but as long as you keep your local copy of the subtree clean &#8211; it is a trivial merge.  Of course then you need to push to origin master since subtrees have a full copy of the subtree in the repo:<\/p>\n<pre>\r\n$ git subtree pull --prefix=static https:\/\/github.com\/csev\/tsugi-static master\r\nremote: Counting objects: 3, done.\r\nremote: Compressing objects: 100% (1\/1), done.\r\nremote: Total 3 (delta 2), reused 3 (delta 2), pack-reused 0\r\nUnpacking objects: 100% (3\/3), done.\r\nFrom https:\/\/github.com\/csev\/tsugi-static\r\n * branch            master     -> FETCH_HEAD\r\nMerge made by the 'recursive' strategy.\r\n static\/README.md | 8 --------\r\n 1 file changed, 8 deletions(-)\r\n\r\n$ git push origin master\r\nCounting objects: 5, done.\r\nDelta compression using up to 8 threads.\r\nCompressing objects: 100% (5\/5), done.\r\nWriting objects: 100% (5\/5), 858 bytes | 0 bytes\/s, done.\r\nTotal 5 (delta 2), reused 0 (delta 0)\r\nTo https:\/\/github.com\/csev\/tsugi.git\r\n   87c5f1d..6397cb5  master -> master\r\n<\/pre>\n<p>And that is all there is to it. <\/p>\n<p>This tricky subtree pull is <strong>only<\/strong> for the repo that pulled in the subtree initially.  Any forks of that repo are unaware that the &#8220;static&#8221; folder is a subtree and for them &#8220;git pull&#8221; updates both the repo and the subtree automatically.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I am starting to build PHP and Java implementations of my Tsugi libraries and I want to share the static content (JavaScript, CSS, etc) between them all so they all are effectively testing the same core code as much as possible and I don&#8217;t want to change things two places. Here are my repos: Static [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4847","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/posts\/4847","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/comments?post=4847"}],"version-history":[{"count":12,"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/posts\/4847\/revisions"}],"predecessor-version":[{"id":4859,"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/posts\/4847\/revisions\/4859"}],"wp:attachment":[{"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/media?parent=4847"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/categories?post=4847"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/tags?post=4847"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}