<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Peter Grainger</title>
    <description>The latest articles on DEV Community by Peter Grainger (@peterjgrainger).</description>
    <link>https://dev.to/peterjgrainger</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F120664%2F4f7346d5-ccdd-4594-a2ac-c1d6fd005365.jpg</url>
      <title>DEV Community: Peter Grainger</title>
      <link>https://dev.to/peterjgrainger</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/peterjgrainger"/>
    <language>en</language>
    <item>
      <title>Microsoft Build 2020- working at home edition</title>
      <dc:creator>Peter Grainger</dc:creator>
      <pubDate>Wed, 20 May 2020 13:11:45 +0000</pubDate>
      <link>https://dev.to/peterjgrainger/microsoft-build-2020-working-at-home-edition-1mc4</link>
      <guid>https://dev.to/peterjgrainger/microsoft-build-2020-working-at-home-edition-1mc4</guid>
      <description>&lt;p&gt;I'm a little sick of reading about "the virus that shall not be named". However, if I wasn't home-bound along with the whole world I very much doubt I would be listening to Microsoft employees and partners talking about what's new with Microsoft. I'm not that interested in flying half way across the globe for a two day conference, there are enough great options in Europe.&lt;/p&gt;

&lt;p&gt;I go to quite a few in person conferences normally and over the past few weeks I've been to a few online ones too. Hopefully I'm in a good position to give a balanced review.&lt;/p&gt;

&lt;h2&gt;
  
  
  So what's new in Microsoft?
&lt;/h2&gt;

&lt;p&gt;Most of my work is either in C++, web development or Azure, so I didn't care about anything to do with office365, teams or Business Intelligence. If you want to know about those products the independent has an OK write up &lt;a href="https://www.independent.co.uk/life-style/gadgets-and-tech/news/microsoft-build-2020-announcement-cloud-conference-news-windows-10-new-features-a9524441.html"&gt;https://www.independent.co.uk/life-style/gadgets-and-tech/news/microsoft-build-2020-announcement-cloud-conference-news-windows-10-new-features-a9524441.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As I'm in the UK I wasn't watching any of this live. Watching a repeat of a live broadcast is not fun. It's like watching a repeat of a football game, you don't feel like you are involved at all. However, the live chat at the side saves it a little bit as you can sometimes get a response to your questions. There seems to be quite a few people in a hoodie, which seems a little forced, I think they are trying to appeal to developers.&lt;/p&gt;

&lt;p&gt;Most of the new features I cared about were first announced were at GitHub Satellite. Which is OK but for the fact I watched GitHub Satellite last week so already knew half of what they were announcing. The rest of the time was spent talking about how Microsoft are working towards having a complete developer system from build to deploy with minimal configuration. There were no bombshells.&lt;/p&gt;

&lt;p&gt;So the "new" features that they kept going on and on about were:&lt;/p&gt;

&lt;h3&gt;
  
  
  Codespaces
&lt;/h3&gt;

&lt;p&gt;Nearly every talk had something to say about codespaces. They take the headache out of setting up your system to work with a repo you don't normally work in. This is great and probably around 90% of slack messages in my organisation. Sign up for the beta here, &lt;a href="https://github.com/features/codespaces"&gt;https://github.com/features/codespaces&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  WSL2
&lt;/h3&gt;

&lt;p&gt;Windows Subsystem Linux (WSL) 2. Microsoft are backtracking on the WSL1 which didn't work as well as they expected. WSL2 is pretty much a linux VM that is accessible easily from the terminal.&lt;/p&gt;

&lt;h3&gt;
  
  
  DevOps Tooling
&lt;/h3&gt;

&lt;p&gt;Not to be confused with the product Azure DevOps but they kept going on and on about how they are doing everything they can to make the feedback loop of coding to deploy to getting feedback on your system as small as possible. Not really an announcement but probably news to some.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I'm liking about Build
&lt;/h2&gt;

&lt;p&gt;Unlike most of the other online conferences it was over 48 hours with content relevant to different timezone and representatives from those timezones. I really appreciate this as most of the online conferences are in American timezone and I need my sleep :) &lt;/p&gt;

&lt;p&gt;I also like how all the talks have a toggle to enable american sign language to accompany them.&lt;/p&gt;

&lt;p&gt;There are different live tracks which are amusingly through teams. All of the presenters are really professional with very little stuttering or awkward pauses that I'm so used to now watching other conferences.&lt;/p&gt;

&lt;p&gt;I had a one-on-one consultation on Azure DevOps which was really useful to get some feedback on one of the applications I'm working on for work.&lt;/p&gt;

&lt;p&gt;The moderators are unbelievable. They answer your questions almost faster than you can write them. There must have been an army behind this conference.&lt;/p&gt;

&lt;p&gt;The recordings are available immediately after broadcast. I always wonder why all the conferences take ages to do this...&lt;/p&gt;

&lt;h2&gt;
  
  
  Made me dive deeply into Blazor
&lt;/h2&gt;

&lt;p&gt;I'd never heard of Blazor before today--not to be confused with Razor the template language. It's a way to make web pages using C# compiling to WASM so it can be ran on a browser. But not only web pages, you can use the framework to create a static front end and linked backend services at the same time.&lt;/p&gt;

&lt;p&gt;I've played with WASM before but I think this is the first time it's been easy. This is one session that I think will have a direct impact on projects I'm working for. Most developer's I'm working with know C# and would probably enjoy writing in it more than JavaScript.&lt;/p&gt;

&lt;p&gt;The Most confusing part is that there is also a project called Razor that is a template engine.&lt;/p&gt;

&lt;h2&gt;
  
  
  Well written learning modules
&lt;/h2&gt;

&lt;p&gt;Microsoft have really well written learning modules, very up to date and thourogh. You can have a look at &lt;a href="https://docs.microsoft.com/en-us/learn"&gt;https://docs.microsoft.com/en-us/learn&lt;/a&gt;. I'm going through a collection on &lt;a href="https://docs.microsoft.com/en-us/users/buildcloudskillschallenge/collections/xemxhp6npy1m67?WT.mc_id=Build2020_csc_RegConfirm-site-mktg&amp;amp;OCID=AID3012653"&gt;languages and frameworks&lt;/a&gt; that I'm really enjoying.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Best Part was a Session on MakeCode with Minecraft
&lt;/h2&gt;

&lt;p&gt;The best part for me so far was the talk on Microsoft MakeCode with Minecraft Blocks. It may be because I have a small child but it was a really good fast paced talk and the presenter &lt;a href="https://github.com/salmanmkc"&gt;Salaman Chishti&lt;/a&gt; seems very genuine. Also &lt;a href="https://arcade.makecode.com/"&gt;MakeCode Arcade&lt;/a&gt; looks really good and I could probably waste many an hour making sprites.&lt;/p&gt;

&lt;p&gt;Also nearly missed the talk by Gene Kim, author of pheonix project. He seems like a really nice guy and I always take something from his talks. Go see that one.&lt;/p&gt;

&lt;h2&gt;
  
  
  And the Worst Part was the Lack of Interactions
&lt;/h2&gt;

&lt;p&gt;The worst part so far is the lack of interaction. Other conferences have gone to great lengths to get participant conversation. Sometimes it feels like I'm just watching videos rather than getting involved in a conference.&lt;/p&gt;

&lt;p&gt;I would like to see more breakout sessions where participants get involved.&lt;/p&gt;

&lt;p&gt;Plus... no swag. Disappointing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Build is Probably the Best Organised Remote Conference
&lt;/h2&gt;

&lt;p&gt;Probably the best organised remote conference I've been to yet. Really embracing the benefits of online. It still felt a little corporate and rehearsed but I didn't expect anything else--I actually expected it to be much worse.&lt;/p&gt;

&lt;p&gt;Some pretty weak announcements compared to those at AWS:Reinvent but the amount of content they put out was really impressive and well organised.&lt;/p&gt;

</description>
      <category>microsoftbuild2020</category>
    </item>
    <item>
      <title>The fascinating world of git cherry-pick</title>
      <dc:creator>Peter Grainger</dc:creator>
      <pubDate>Fri, 28 Feb 2020 16:34:00 +0000</pubDate>
      <link>https://dev.to/peterjgrainger/the-fascinating-world-of-git-cherry-pick-11d4</link>
      <guid>https://dev.to/peterjgrainger/the-fascinating-world-of-git-cherry-pick-11d4</guid>
      <description>&lt;p&gt;The following is taken directly from &lt;a href="https://en.wikipedia.org/wiki/Git"&gt;the wikipedia article about Git&lt;/a&gt; and pretty much sums up my week.&lt;/p&gt;

&lt;p&gt;The name "git" was given by Linus Torvalds when he wrote the very first version. He described the tool as "the stupid content tracker" and the name as (depending on your way):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;random three-letter combination that is pronounceable, and not actually used by any common UNIX command. The fact that it is a mispronunciation of "get" may or may not be relevant.&lt;/li&gt;
&lt;li&gt;stupid. contemptible and despicable. simple. Take your pick from the dictionary of slang.&lt;/li&gt;
&lt;li&gt;"global information tracker": you're in a good mood, and it actually works for you. Angels sing, and a light suddenly fills the room.&lt;/li&gt;
&lt;li&gt;"goddamn idiotic truckload of sh*t": when it breaks&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  I love Git
&lt;/h2&gt;

&lt;p&gt;Like many of my friends and coworkers, I have a love and hate relationship with Git--mainly hate. However, Git is probably the best and most used source control system out there so we have to use it :)&lt;/p&gt;

&lt;h2&gt;
  
  
  Apply Changes Introduced by Some Existing Commits.
&lt;/h2&gt;

&lt;p&gt;According to the &lt;a href="https://git-scm.com/docs/git-cherry-pick"&gt;Git docs&lt;/a&gt; the action of the &lt;code&gt;git cherry-check&lt;/code&gt; command is to "Apply the changes introduced by some existing commits". Notice the use of the phrase &lt;em&gt;apply changes&lt;/em&gt; rather than &lt;em&gt;merge changes&lt;/em&gt;. Cherry picking will not preserve history exactly how it is represented from the source. This will record a new commit SHA.&lt;/p&gt;

&lt;h2&gt;
  
  
  Avoid Cherry Picking Commits if you can.
&lt;/h2&gt;

&lt;p&gt;Using the &lt;code&gt;git cherry-pick&lt;/code&gt; command should be a last resort and should be avoided if you can use merge. Cherry picking should only be done either if the source has a completely different history and you want the changes from a single commit and don't care about preserving the history.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Syntax for Cherry Pick is straight forward
&lt;/h2&gt;

&lt;p&gt;If you are still keen to go ahead with the &lt;code&gt;cherry-pick&lt;/code&gt; the syntax is straight forward.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git cherry-pick &amp;lt;commit&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;That's it--as long as you don't have any conflicts or if it's a merge commit.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using Cherry Pick on a Merge Commit
&lt;/h2&gt;

&lt;p&gt;If the commit you want to &lt;code&gt;cherry-pick&lt;/code&gt; is a merge commit then add the flag --parent-number &lt;/p&gt;

&lt;p&gt;What is this number I hear you ask? The short answer is--always make it 1. The long answer is in this &lt;a href="https://stackoverflow.com/questions/12626754/git-cherry-pick-syntax-and-merge-branches/12628579#12628579"&gt;SO post&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;But just use the number &lt;code&gt;1&lt;/code&gt;. It has never failed me :)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git cherry-pick -m 1 &amp;lt;commit&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Pick More Than One Commit
&lt;/h2&gt;

&lt;p&gt;If you are feeling more adventurous you can Cherry Pick a &lt;em&gt;range&lt;/em&gt; of commits.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git cherry-pick &amp;lt;oldest-commit&amp;gt;..&amp;lt;newest-commit&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This will cherry pick each commit from the one &lt;em&gt;after&lt;/em&gt; the &lt;code&gt;oldest-commit&lt;/code&gt; to the  &lt;code&gt;newest-commit&lt;/code&gt;. The &lt;code&gt;cherry-pick&lt;/code&gt; will &lt;em&gt;not&lt;/em&gt; include the &lt;code&gt;oldest-commit&lt;/code&gt; but &lt;em&gt;will&lt;/em&gt; include the &lt;code&gt;newest-commit&lt;/code&gt;--confusing :s&lt;/p&gt;

&lt;h2&gt;
  
  
  Just Touched the Surface of What is Available
&lt;/h2&gt;

&lt;p&gt;I've just touched the surface of what &lt;code&gt;git cherry-pick&lt;/code&gt; can do, setting up how merge conflicts are handled deserve their own post!&lt;/p&gt;

</description>
      <category>git</category>
    </item>
    <item>
      <title>Git Merge: friend or fiend?</title>
      <dc:creator>Peter Grainger</dc:creator>
      <pubDate>Sat, 15 Feb 2020 06:32:43 +0000</pubDate>
      <link>https://dev.to/peterjgrainger/git-merge-friend-or-fiend-4pd0</link>
      <guid>https://dev.to/peterjgrainger/git-merge-friend-or-fiend-4pd0</guid>
      <description>&lt;p&gt;A little knowledge is a dangerous thing. When I first learnt to drive, I thought I was a 17 year old version of &lt;a href="https://en.wikipedia.org/wiki/Michael_Schumacher"&gt;Michael Schumacher&lt;/a&gt;, one of the best formula one racers of the time. I look back on those years of driving around with my friends and I'm terrified! How did I survive!&lt;/p&gt;

&lt;p&gt;I feel a little like that now looking back on what I "knew" about Git last week and what I know now. &lt;code&gt;git merge&lt;/code&gt; started out on Monday as a fiend but on Friday I welcomed it into my life like a long lost friend because of some great power features that make my life much easier now I understand it a little better.&lt;/p&gt;

&lt;h2&gt;
  
  
  Git Merge Comes As Standard
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;git merge&lt;/code&gt; is a command that comes as standard when you install git. It's used for merging one or more commits into the branch you have currently checked out. It's most commonly used for merging one branch into another one. For example merging your feature back into the &lt;code&gt;master&lt;/code&gt; branch.&lt;/p&gt;

&lt;h2&gt;
  
  
  Merge Lots of Branches At the Same Time
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;git merge &amp;lt;commit-sha-1&amp;gt; &amp;lt;commit-sha-2&amp;gt;&lt;/code&gt; will merge as many commits as you like! This uses the merge strategy &lt;code&gt;octopus&lt;/code&gt;, by default. You'll probably not need to know what it does exactly, but it's the default-and it sounds cool.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use the Branch or Tag Identifier Instead of SHA
&lt;/h2&gt;

&lt;p&gt;You can use a branch identifier like &lt;code&gt;develop&lt;/code&gt; or a tag like &lt;code&gt;v1.0.0&lt;/code&gt; instead of going to the trouble of finding a specific commit SHA :)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;git&lt;/span&gt; &lt;span class="nx"&gt;merge&lt;/span&gt; &lt;span class="nx"&gt;v1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mf"&gt;2.3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;I needed to merge multiple tags together and it would have been a real pain if this feature wasn't there.&lt;/p&gt;

&lt;h2&gt;
  
  
  Specify Different Merge Strategies
&lt;/h2&gt;

&lt;p&gt;By default &lt;code&gt;git merge&lt;/code&gt; uses a &lt;code&gt;recursive&lt;/code&gt; merge. All you need to know is that it is the one that avoids the most conflicts.&lt;/p&gt;

&lt;p&gt;There are other strategies. Using the strategy &lt;code&gt;ours&lt;/code&gt; uses the current branch changes over the one being merged in if there are any conflicting changes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git merge --strategy ours 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You can also specify &lt;code&gt;theirs&lt;/code&gt; as a strategy to take the changes from the incoming branch.&lt;/p&gt;

&lt;h2&gt;
  
  
  Merge Branches That Have No Common History
&lt;/h2&gt;

&lt;p&gt;Most of the time you will be using &lt;code&gt;git merge&lt;/code&gt; inside one repository but you don't have to limit yourself. By adding a second remote you can merge any branch from any other repository with the flag &lt;code&gt;allow-unrelated-histories&lt;/code&gt;. One caveat, if you have the same filenames in both repositories get ready for lots of merge conflicts. :)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git remote add other-repo git@github.com:peterjgrainger/other-repo.git
git merge other-repo/master --allow-unrelated-histories
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Loads More Great Features
&lt;/h2&gt;

&lt;p&gt;I realise now that I know nothing about git, I've only scratched the surface. If you want to read more about &lt;code&gt;git merge&lt;/code&gt; see the documentation &lt;a href="https://git-scm.com/docs/git-merge"&gt;https://git-scm.com/docs/git-merge&lt;/a&gt;. It's not the most interesting read but a good reference.&lt;/p&gt;

</description>
      <category>gitgitmergemerge</category>
    </item>
    <item>
      <title>Monorepo: How to keep your history in order</title>
      <dc:creator>Peter Grainger</dc:creator>
      <pubDate>Fri, 07 Feb 2020 14:10:27 +0000</pubDate>
      <link>https://dev.to/peterjgrainger/monorepo-how-to-keep-your-history-in-order-58il</link>
      <guid>https://dev.to/peterjgrainger/monorepo-how-to-keep-your-history-in-order-58il</guid>
      <description>&lt;p&gt;Can you really rely on history to be accurate? History is written by the winners not the losers. I'm a massive fan of the &lt;a href="https://en.wikipedia.org/wiki/Vikings_(2013_TV_series)"&gt;Vikings&lt;/a&gt;. I love historical TV series but the more I looked into the actual facts about the time the more I realised much of the series was based around rumours and myths. There is a distinct lack of paper and pens in the fiords of Norway in that time period. Even if they had the equipment, I doubt they would care that much to write down every detail. So who writes the history then? The conquering nations who do care about writing things down, that's who!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ln0Gbkg2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/z308788il1ghlyeip0s9.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ln0Gbkg2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/z308788il1ghlyeip0s9.jpg" alt="Viking"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So like those conquers of the past we are going to re-write history--Git history :)&lt;/p&gt;

&lt;p&gt;In this post I'll explain how I converted multiple Git repositories into one repository by gluing together two different solutions.&lt;/p&gt;

&lt;h2&gt;
  
  
  My project
&lt;/h2&gt;

&lt;p&gt;My current setup consisted of multiple repositories with a few characteristics that caused a few headaches in this process:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Most of the repositories had 2000+ commits in each&lt;/li&gt;
&lt;li&gt;Repositories were reliant on each other and had branches with the same name that related to each other, e.g. &lt;code&gt;release-123&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;There were about 20 different repositories&lt;/li&gt;
&lt;li&gt;The history was important&lt;/li&gt;
&lt;li&gt;There were lots of branches, most stale.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Reusing Others Hard Work
&lt;/h2&gt;

&lt;p&gt;The first thing I did when approaching this task was to re-use as much from others who have attempted this before.&lt;/p&gt;

&lt;p&gt;There are some great tools to convert the structure of your repos from multi to monorepos. I'll discuss &lt;a href="https://github.com/hraban/tomono"&gt;tomono&lt;/a&gt; and &lt;a href="https://www.shopsys.com/how-to-merge-15-repositories-to-1-monorepo-keep-their-git-history-and-add-project-base-as-well-6e124f3a0ab3/"&gt;ShopSys&lt;/a&gt;. Tomono is simpler but shopsys has fuller features, both didn't really work for me.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tomono
&lt;/h2&gt;

&lt;p&gt;The tomono script is first. I noticed late on that the history wasn't actually being re-written (by design) and was relies on the built in mechanisms of git merge. I would probably agree with the maintainer that this is a &lt;a href="https://github.com/hraban/tomono/issues/6"&gt;bug in git&lt;/a&gt; not the scripts but it doesn't help me right now.&lt;/p&gt;

&lt;h2&gt;
  
  
  Shopsys
&lt;/h2&gt;

&lt;p&gt;Next to the shopsys tools. These scripts &lt;em&gt;do&lt;/em&gt; re-write history but they only merge the master branch. As my setup is weird and I need to merge &lt;em&gt;any&lt;/em&gt; branch that has the same name. I can't use these scripts out of the box either.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating a Monster
&lt;/h2&gt;

&lt;p&gt;Like Frankenstein my requirements were for something that didn't exist. I've got a good start but need to take the best parts from each script and combine them to create a monster script. I'll warn you now--like Frankenstein's monster this script is not the prettiest or most efficient but it gets the job done. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--h7v9Q3cG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://upload.wikimedia.org/wikipedia/commons/thumb/c/c2/Frankenstein%252C_pg_7.jpg/1280px-Frankenstein%252C_pg_7.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--h7v9Q3cG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://upload.wikimedia.org/wikipedia/commons/thumb/c/c2/Frankenstein%252C_pg_7.jpg/1280px-Frankenstein%252C_pg_7.jpg" alt="Frankenstein (1922 book)"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  It's alive
&lt;/h2&gt;

&lt;p&gt;The magic from the shopsys script comes from the script &lt;a href="https://github.com/shopsys/monorepo-tools/blob/master/rewrite_history_into.sh"&gt;&lt;code&gt;rewrite-history-into&lt;/code&gt;&lt;/a&gt; which uses &lt;code&gt;git filter-branch&lt;/code&gt; to rewrite the Git history to move everything into a subfolder.&lt;/p&gt;

&lt;p&gt;I call the shopsys script from a &lt;a href="https://github.com/arup-group/tomono/blob/c9e7dfede85a0d010eeca02db068f326e0689a9d/tomono.sh#L163"&gt;modified tomono script&lt;/a&gt; to re-write the history for each branch. I've shown the interesting parts below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# tomono.sh&lt;/span&gt;
git checkout &lt;span class="nt"&gt;-q&lt;/span&gt; &lt;span class="nv"&gt;$name&lt;/span&gt;/&lt;span class="nv"&gt;$branch&lt;/span&gt; &lt;span class="c"&gt;# checkout the remote branch which will be a subfolder&lt;/span&gt;
../monorepo-tools/rewrite_history_into.sh &lt;span class="nv"&gt;$name&lt;/span&gt; &lt;span class="c"&gt;# re-write the history&lt;/span&gt;
git switch &lt;span class="nt"&gt;-q&lt;/span&gt; &lt;span class="nt"&gt;-c&lt;/span&gt; temp-munge-branch &lt;span class="c"&gt;# make a temp branch to store the changes&lt;/span&gt;
git checkout &lt;span class="nt"&gt;-q&lt;/span&gt; &lt;span class="nv"&gt;$branch&lt;/span&gt; &lt;span class="c"&gt;# Go back to the base repo&lt;/span&gt;
git reset &lt;span class="nt"&gt;-q&lt;/span&gt; &lt;span class="nt"&gt;--hard&lt;/span&gt; &lt;span class="c"&gt;# get rid of any changes&lt;/span&gt;
git merge &lt;span class="nt"&gt;-q&lt;/span&gt; &lt;span class="nt"&gt;--no-commit&lt;/span&gt; temp-munge-branch &lt;span class="nt"&gt;--allow-unrelated-histories&lt;/span&gt; &lt;span class="c"&gt;# Do the merge!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Now for the downside
&lt;/h2&gt;

&lt;p&gt;This script is &lt;em&gt;painfully&lt;/em&gt; slow. It takes &lt;em&gt;hours&lt;/em&gt; to run. I'm sure there are optimisations I can make but as I'm only running this once i don't really care.&lt;/p&gt;

&lt;p&gt;My script also includes some logic around which branches to move over. You might want to clean up your branches before the move but I'm lazy and just avoided transferring those branches.&lt;/p&gt;

&lt;h2&gt;
  
  
  Expectation vs Reality
&lt;/h2&gt;

&lt;p&gt;Current scripts are good but can't account for every scenario. If you are in the same scenario as me I hope this helps. There is a high chance you have a slightly different use case so be sure to allow enough time for your transition so you don't rush it and make a mistake!&lt;/p&gt;

&lt;h1&gt;
  
  
  Found a typo?
&lt;/h1&gt;

&lt;p&gt;If you've found a typo, a sentence that could be improved or anything else that should be updated on this blog post, you can access it through a git repository and make a pull request. Instead of posting a comment, please go directly to &lt;a href="https://github.com/peterjgrainger/dev-to-posts/blob/master/blog-posts/monorepo-keeping-your-history-in-order/monorepo-keeping-your-history-in-order.md"&gt;https://github.com/peterjgrainger/dev-to-posts/blob/master/blog-posts/monorepo-keeping-your-history-in-order/monorepo-keeping-your-history-in-order.md&lt;/a&gt; and open a new pull request with your changes.&lt;/p&gt;

</description>
      <category>monorepo</category>
      <category>git</category>
      <category>github</category>
    </item>
  </channel>
</rss>
