{"id":15104,"date":"2022-08-26T13:25:57","date_gmt":"2022-08-26T10:25:57","guid":{"rendered":"https:\/\/railsware.com\/blog\/?p=15104"},"modified":"2023-02-07T16:09:17","modified_gmt":"2023-02-07T13:09:17","slug":"how-to-use-git-rebase-onto","status":"publish","type":"post","link":"https:\/\/railsware.com\/blog\/how-to-use-git-rebase-onto\/","title":{"rendered":"New Level of Control with git rebase \u2011\u2011onto"},"content":{"rendered":"\n<div class=\"intro-text\">Git rebase is a great tool to rearrange your commit history and make it tidier. But during my long history of using it, I collected a bunch of use cases that were hard to handle with a usual rebase. It turns out that <em>rebase<\/em> has a little-known option <em>\u2011\u2011onto<\/em> which was a game changer for me.<\/div>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"538\" src=\"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2022\/08\/Git-onto_Featured-image_2400x1260-1024x538.jpg\" alt=\"\" class=\"wp-image-15101\" srcset=\"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2022\/08\/Git-onto_Featured-image_2400x1260-1024x538.jpg 1024w, https:\/\/railsware.com\/blog\/wp-content\/uploads\/2022\/08\/Git-onto_Featured-image_2400x1260-360x189.jpg 360w, https:\/\/railsware.com\/blog\/wp-content\/uploads\/2022\/08\/Git-onto_Featured-image_2400x1260-768x403.jpg 768w, https:\/\/railsware.com\/blog\/wp-content\/uploads\/2022\/08\/Git-onto_Featured-image_2400x1260-1536x806.jpg 1536w, https:\/\/railsware.com\/blog\/wp-content\/uploads\/2022\/08\/Git-onto_Featured-image_2400x1260-2048x1075.jpg 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">In a nutshell, <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;git rebase \u2011\u2011onto<\/code><\/code> allows you to move or copy a bunch of commits from one branch atop another. You can treat it as a <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;git cherry-pick<\/code><\/code> on steroids. Without further ado, let&#8217;s see it in action.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What\u2019s the problem with <em>rebase<\/em><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Imagine, there is a branch <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;feature1<\/code><\/code>, that was created by your colleague. Your goal is to add some new stuff to it. You happily branched off of <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;feature1<\/code><\/code> and implemented new functionality in commits <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;C<\/code><\/code> and <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;D<\/code><\/code>. Here is what Git history looks like:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\" data-line=\"\">A --- B feature1\n       \\     \n        C --- D feature2<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">While you worked on your stuff, your colleague added some new functionality in <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;feature1<\/code><\/code>. But they also like to use rebase, so they modified commit <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;B<\/code><\/code> a bit. On the diagram below, it&#8217;s named <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;B*<\/code><\/code>. Here is what the working tree looks like now:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\" data-line=\"\">A --- B* --- E --- F feature1\n \\     \n  B --- C --- D feature2<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You need to catch up with their changes, so you decided to rebase:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\" data-line=\"\">git rebase feature1<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">And now the bummer &#8211; you caught a conflict between <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;B<\/code><\/code> and <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;B<\/code><\/code>* and need to resolve it. Sound familiar?<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Solving the issue with <em>git rebase \u2011\u2011onto<\/em><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before blaming your colleague, you need to realize that the issue is not with the change itself. The issue lies in the way standard <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;rebase<\/code><\/code> does its job. In the example above, rebase takes <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;feature1<\/code><\/code> as a starting point and then tries to apply all new commits atop.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In other words, it takes commit <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;F<\/code><\/code> as a new starting point. Then, it finds the place where both branches have diverged. In our case, it&#8217;s commit <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;A<\/code><\/code>. So, <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;rebase<\/code><\/code> takes commits <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;B<\/code><\/code>, <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;C<\/code><\/code>, and <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;D<\/code><\/code>, and one by one, tries to add them on top of commit <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;F<\/code><\/code>. The diff for commit <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;B<\/code><\/code> cannot be applied to existing source tree and thus we need to resolve the conflict.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Ideally, we want to avoid resolving the conflict and just get the next history tree:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\" data-line=\"\">A --- B* --- E --- F feature1\n                    \\     \n                     C&#039; --- D&#039; feature2<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">(Notice: <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;C<\/code><\/code>&#8216; and <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;D<\/code><\/code>&#8216; have the same changesets as <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;C<\/code><\/code> and <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;D<\/code><\/code> but we updated the naming to reflect changes in <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;SHA<\/code><\/code>)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So, we want to take commits<code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt; C<\/code><\/code> and <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;D<\/code><\/code> and attach them on top of <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;feature1<\/code><\/code>, ignoring the previous history altogether. This can be achieved by git cherry-pick, but it&#8217;s a tedious and error-prone job.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Instead, we can use <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;git rebase \u2011\u2011onto<\/code><\/code>. We need to be on <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;feature2<\/code><\/code> and execute this command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\" data-line=\"\">git checkout feature2\ngit rebase --onto feature1 B<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That means: take all commits after commit <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;B<\/code><\/code> (in our case it will be <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;C<\/code><\/code> and <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;D<\/code><\/code>) and place them atop of <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;feature1<\/code><\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">After applying this command, we&#8217;ll get the desired working tree without the need to resolve the conflict between <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;B<\/code><\/code> and <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;B*.<\/code><\/code> We can still have a conflict if <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;C<\/code><\/code> or <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;D<\/code><\/code> conflicts with <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;B*<\/code><\/code>, <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;E,<\/code><\/code> or <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;F<\/code><\/code>, but that&#8217;s a normal case.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Instead of providing<code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt; B<\/code><\/code> as the second argument, we can use relative addressing with <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;HEAD~N<\/code><\/code>. For our example it will be:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\" data-line=\"\">git checkout feature2\ngit rebase \u2011\u2011onto feature1 HEAD~2<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That can be read as: take two last commits from my branch and put them atop of <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;feature1<\/code><\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Solving the problem of branching from a wrong place<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">There are many cases when you can start your work in the wrong place or for some reason you need to move your commits to a totally different place.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here\u2019s a widespread example. You branched off of <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;main<\/code><\/code> branch, but suddenly a product manager tells you that your stuff is critical for production and you need to change the base of your branch to <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;hotfix<\/code><\/code> instead. Here is a commit history:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\" data-line=\"\">       E --- F --- G feature\n       \/\nA --- B main\n \\\n  C --- D hotfix<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You need to get the next history instead:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\" data-line=\"\">A --- B main\n \\\n  C --- D hotfix\n         \\\n          E&#039; --- F&#039; --- G&#039; feature<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">(Notice: <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;E&#039;<\/code><\/code>, <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;F&#039;<\/code><\/code>, and <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;G&#039;<\/code><\/code> have the same changesets as <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;E,<\/code><\/code> <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;F<\/code><\/code>, and <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;G<\/code><\/code> but we updated the naming to reflect changes in <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;SHA<\/code><\/code>)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you use regular <code class=\"\" data-line=\"\">rebase<\/code>, commit <code class=\"\" data-line=\"\">B <\/code>will sneak into <code class=\"\" data-line=\"\">hotfix<\/code> branch. In practice, <code class=\"\" data-line=\"\">main<\/code> branch can have dozens of other features merged and you would bring all of them into <code class=\"\" data-line=\"\">hotfix<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">But <code class=\"\" data-line=\"\">git rebase \u2011\u2011onto<\/code> does not have this issue. Here is a solution:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\" data-line=\"\">git checkout feature\ngit rebase \u2011\u2011onto hotfix B<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">or the same with relative addressing:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\" data-line=\"\">git checkout feature\ngit rebase \u2011\u2011onto hotfix HEAD~3<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Actually, almost all cases of moving around commits can be handled with <code class=\"\" data-line=\"\">&lt;code data-enlighter-language=&quot;generic&quot; class=&quot;EnlighterJSRAW&quot;&gt;\u2011\u2011onto<\/code><\/code> option.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Dropping commits<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">For the sake of completeness, let&#8217;s discuss how to remove commits with <code class=\"\" data-line=\"\">\u2011\u2011onto<\/code> option. Here is an example of a working tree:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\" data-line=\"\">A \u2011\u2011\u2011 B \u2011\u2011\u2011 C \u2011\u2011\u2011 D \u2011\u2011\u2011 E&nbsp; feature<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">We want to remove commits <code class=\"\" data-line=\"\">C<\/code> and <code class=\"\" data-line=\"\">D<\/code> to obtain the next commit history:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\" data-line=\"\">A \u2011\u2011\u2011 B \u2011\u2011\u2011 E&#039;&nbsp; feature<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">(Notice: <code class=\"\" data-line=\"\">E<\/code> and E&#8217; have the same changeset, but <code class=\"\" data-line=\"\">E&#039;<\/code> has another <code class=\"\" data-line=\"\">SHA<\/code> due to a change in commit history)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here is the solution:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\" data-line=\"\">git checkout feature\ngit rebase \u2011\u2011onto B HEAD~1<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">A word of caution<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Using <code class=\"\" data-line=\"\">rebase<\/code> always has the risk of doing something wrong and losing your commits. If you are still new to this tool, be sure to follow the usual safety measures: keep SHA of the HEAD of your branch before doing rebase or be fluent with using <code class=\"\" data-line=\"\">git reflog<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">As I said, <code class=\"\" data-line=\"\">git rebase \u2011\u2011onto<\/code> greatly improved my commit housekeeping experience and removed a lot of pain points I had before. Despite the logic of <code class=\"\" data-line=\"\">\u2011\u2011onto<\/code> option being quite simple, it took me some time to find a proper way and practical understanding of how to use it in various scenarios.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So I hope this article will save you some time and extend your Git tricks collection.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A simple tutorial on how to use git rebase &#8211;onto to easily move or copy a bunch of commits from one branch atop another<\/p>\n","protected":false},"author":25,"featured_media":15103,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[3],"tags":[],"coauthors":["Sergii Boiko"],"class_list":["post-15104","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-development"],"acf":[],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.9 - aioseo.com -->\n\t<meta name=\"description\" content=\"A simple tutorial on how to use git rebase --onto to easily move or copy a bunch of commits from one branch atop another\" \/>\n\t<meta name=\"robots\" content=\"max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n\t<meta name=\"author\" content=\"Sergii Boiko\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/railsware.com\/blog\/how-to-use-git-rebase-onto\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.9\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"| Blog on Engineering, Product Management, Transparency, Culture and many more...\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"How to use git rebase\u2011\u2011onto\" \/>\n\t\t<meta property=\"og:description\" content=\"A simple tutorial on how to use git rebase --onto to easily move or copy a bunch of commits from one branch atop another\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/railsware.com\/blog\/how-to-use-git-rebase-onto\/\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2022\/08\/Icon_360x360.png\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2022\/08\/Icon_360x360.png\" \/>\n\t\t<meta property=\"og:image:width\" content=\"361\" \/>\n\t\t<meta property=\"og:image:height\" content=\"360\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2022-08-26T10:25:57+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2023-02-07T13:09:17+00:00\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/how-to-use-git-rebase-onto\\\/#article\",\"name\":\"How to use git rebase\\u2011\\u2011onto\",\"headline\":\"New Level of Control with git rebase \\u2011\\u2011onto\",\"author\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/author\\\/sergii-boiko\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/#organization\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/railsware.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/Icon_360x360.png\",\"width\":361,\"height\":360},\"datePublished\":\"2022-08-26T13:25:57+03:00\",\"dateModified\":\"2023-02-07T16:09:17+03:00\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/how-to-use-git-rebase-onto\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/how-to-use-git-rebase-onto\\\/#webpage\"},\"articleSection\":\"Engineering\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/how-to-use-git-rebase-onto\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/railsware.com\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/category\\\/development\\\/#listItem\",\"name\":\"Engineering\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/category\\\/development\\\/#listItem\",\"position\":2,\"name\":\"Engineering\",\"item\":\"https:\\\/\\\/railsware.com\\\/blog\\\/category\\\/development\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/how-to-use-git-rebase-onto\\\/#listItem\",\"name\":\"New Level of Control with git rebase \\u2011\\u2011onto\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/how-to-use-git-rebase-onto\\\/#listItem\",\"position\":3,\"name\":\"New Level of Control with git rebase \\u2011\\u2011onto\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/category\\\/development\\\/#listItem\",\"name\":\"Engineering\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/#organization\",\"description\":\"Blog on Engineering, Product Management, Transparency, Culture and many more...\",\"url\":\"https:\\\/\\\/railsware.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/railsware.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/11\\\/Logo-circle.png\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/how-to-use-git-rebase-onto\\\/#organizationLogo\",\"width\":3137,\"height\":1054,\"caption\":\"Railsware logo\"},\"image\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/how-to-use-git-rebase-onto\\\/#organizationLogo\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/author\\\/sergii-boiko\\\/#author\",\"url\":\"https:\\\/\\\/railsware.com\\\/blog\\\/author\\\/sergii-boiko\\\/\",\"name\":\"Sergii Boiko\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/how-to-use-git-rebase-onto\\\/#authorImage\",\"url\":\"https:\\\/\\\/railsware.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/06\\\/sergii-boiko-96x96.jpg\",\"width\":96,\"height\":96,\"caption\":\"Sergii Boiko\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/how-to-use-git-rebase-onto\\\/#webpage\",\"url\":\"https:\\\/\\\/railsware.com\\\/blog\\\/how-to-use-git-rebase-onto\\\/\",\"name\":\"How to use git rebase\\u2011\\u2011onto\",\"description\":\"A simple tutorial on how to use git rebase --onto to easily move or copy a bunch of commits from one branch atop another\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/how-to-use-git-rebase-onto\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/author\\\/sergii-boiko\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/author\\\/sergii-boiko\\\/#author\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/railsware.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/Icon_360x360.png\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/how-to-use-git-rebase-onto\\\/#mainImage\",\"width\":361,\"height\":360},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/how-to-use-git-rebase-onto\\\/#mainImage\"},\"datePublished\":\"2022-08-26T13:25:57+03:00\",\"dateModified\":\"2023-02-07T16:09:17+03:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/railsware.com\\\/blog\\\/\",\"description\":\"Blog on Engineering, Product Management, Transparency, Culture and many more...\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"How to use git rebase\u2011\u2011onto","description":"A simple tutorial on how to use git rebase --onto to easily move or copy a bunch of commits from one branch atop another","canonical_url":"https:\/\/railsware.com\/blog\/how-to-use-git-rebase-onto\/","robots":"max-snippet:-1, max-image-preview:large, max-video-preview:-1","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/railsware.com\/blog\/how-to-use-git-rebase-onto\/#article","name":"How to use git rebase\u2011\u2011onto","headline":"New Level of Control with git rebase \u2011\u2011onto","author":{"@id":"https:\/\/railsware.com\/blog\/author\/sergii-boiko\/#author"},"publisher":{"@id":"https:\/\/railsware.com\/blog\/#organization"},"image":{"@type":"ImageObject","url":"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2022\/08\/Icon_360x360.png","width":361,"height":360},"datePublished":"2022-08-26T13:25:57+03:00","dateModified":"2023-02-07T16:09:17+03:00","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/railsware.com\/blog\/how-to-use-git-rebase-onto\/#webpage"},"isPartOf":{"@id":"https:\/\/railsware.com\/blog\/how-to-use-git-rebase-onto\/#webpage"},"articleSection":"Engineering"},{"@type":"BreadcrumbList","@id":"https:\/\/railsware.com\/blog\/how-to-use-git-rebase-onto\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/railsware.com\/blog#listItem","position":1,"name":"Home","item":"https:\/\/railsware.com\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/railsware.com\/blog\/category\/development\/#listItem","name":"Engineering"}},{"@type":"ListItem","@id":"https:\/\/railsware.com\/blog\/category\/development\/#listItem","position":2,"name":"Engineering","item":"https:\/\/railsware.com\/blog\/category\/development\/","nextItem":{"@type":"ListItem","@id":"https:\/\/railsware.com\/blog\/how-to-use-git-rebase-onto\/#listItem","name":"New Level of Control with git rebase \u2011\u2011onto"},"previousItem":{"@type":"ListItem","@id":"https:\/\/railsware.com\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/railsware.com\/blog\/how-to-use-git-rebase-onto\/#listItem","position":3,"name":"New Level of Control with git rebase \u2011\u2011onto","previousItem":{"@type":"ListItem","@id":"https:\/\/railsware.com\/blog\/category\/development\/#listItem","name":"Engineering"}}]},{"@type":"Organization","@id":"https:\/\/railsware.com\/blog\/#organization","description":"Blog on Engineering, Product Management, Transparency, Culture and many more...","url":"https:\/\/railsware.com\/blog\/","logo":{"@type":"ImageObject","url":"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2020\/11\/Logo-circle.png","@id":"https:\/\/railsware.com\/blog\/how-to-use-git-rebase-onto\/#organizationLogo","width":3137,"height":1054,"caption":"Railsware logo"},"image":{"@id":"https:\/\/railsware.com\/blog\/how-to-use-git-rebase-onto\/#organizationLogo"}},{"@type":"Person","@id":"https:\/\/railsware.com\/blog\/author\/sergii-boiko\/#author","url":"https:\/\/railsware.com\/blog\/author\/sergii-boiko\/","name":"Sergii Boiko","image":{"@type":"ImageObject","@id":"https:\/\/railsware.com\/blog\/how-to-use-git-rebase-onto\/#authorImage","url":"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2021\/06\/sergii-boiko-96x96.jpg","width":96,"height":96,"caption":"Sergii Boiko"}},{"@type":"WebPage","@id":"https:\/\/railsware.com\/blog\/how-to-use-git-rebase-onto\/#webpage","url":"https:\/\/railsware.com\/blog\/how-to-use-git-rebase-onto\/","name":"How to use git rebase\u2011\u2011onto","description":"A simple tutorial on how to use git rebase --onto to easily move or copy a bunch of commits from one branch atop another","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/railsware.com\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/railsware.com\/blog\/how-to-use-git-rebase-onto\/#breadcrumblist"},"author":{"@id":"https:\/\/railsware.com\/blog\/author\/sergii-boiko\/#author"},"creator":{"@id":"https:\/\/railsware.com\/blog\/author\/sergii-boiko\/#author"},"image":{"@type":"ImageObject","url":"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2022\/08\/Icon_360x360.png","@id":"https:\/\/railsware.com\/blog\/how-to-use-git-rebase-onto\/#mainImage","width":361,"height":360},"primaryImageOfPage":{"@id":"https:\/\/railsware.com\/blog\/how-to-use-git-rebase-onto\/#mainImage"},"datePublished":"2022-08-26T13:25:57+03:00","dateModified":"2023-02-07T16:09:17+03:00"},{"@type":"WebSite","@id":"https:\/\/railsware.com\/blog\/#website","url":"https:\/\/railsware.com\/blog\/","description":"Blog on Engineering, Product Management, Transparency, Culture and many more...","inLanguage":"en-US","publisher":{"@id":"https:\/\/railsware.com\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"| Blog on Engineering, Product Management, Transparency, Culture and many more...","og:type":"article","og:title":"How to use git rebase\u2011\u2011onto","og:description":"A simple tutorial on how to use git rebase --onto to easily move or copy a bunch of commits from one branch atop another","og:url":"https:\/\/railsware.com\/blog\/how-to-use-git-rebase-onto\/","og:image":"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2022\/08\/Icon_360x360.png","og:image:secure_url":"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2022\/08\/Icon_360x360.png","og:image:width":361,"og:image:height":360,"article:published_time":"2022-08-26T10:25:57+00:00","article:modified_time":"2023-02-07T13:09:17+00:00"},"aioseo_meta_data":{"post_id":"15104","title":"How to use git rebase\u2011\u2011onto","description":"A simple tutorial on how to use git rebase --onto to easily move or copy a bunch of commits from one branch atop another","keywords":[],"keyphrases":{"focus":{"keyphrase":"","score":0,"analysis":{"keyphraseInTitle":{"score":0,"maxScore":9,"error":1}}},"additional":[]},"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":[],"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":{"id":"aioseo-article-6385f9c4ef484","slug":"article","graphName":"Article","label":"Article","properties":{"type":"BlogPosting","name":"#post_title","headline":"#post_title","description":"#post_excerpt","image":"","keywords":"","author":{"name":"#author_name","url":"#author_url"},"dates":{"include":true,"datePublished":"","dateModified":""}}},"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":"{\"article\":{\"articleType\":\"BlogPosting\"},\"course\":{\"name\":\"\",\"description\":\"\",\"provider\":\"\"},\"faq\":{\"pages\":[]},\"product\":{\"reviews\":[]},\"recipe\":{\"ingredients\":[],\"instructions\":[],\"keywords\":[]},\"software\":{\"reviews\":[],\"operatingSystems\":[]},\"webPage\":{\"webPageType\":\"WebPage\"},\"blockGraphs\":[]}","pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":null,"frequency":"default","location":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2022-08-26 09:44:10","updated":"2025-09-26 11:35:39","seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/railsware.com\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/railsware.com\/blog\/category\/development\/\" title=\"Engineering\">Engineering<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tNew Level of Control with git rebase \u2011\u2011onto\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/railsware.com\/blog"},{"label":"Engineering","link":"https:\/\/railsware.com\/blog\/category\/development\/"},{"label":"New Level of Control with git rebase \u2011\u2011onto","link":"https:\/\/railsware.com\/blog\/how-to-use-git-rebase-onto\/"}],"categories_data":[{"name":"Engineering","link":"https:\/\/railsware.com\/blog?category=development"}],"post_thumbnails":"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2022\/08\/Icon_360x360.png","article_background":"","amp_enabled":true,"_links":{"self":[{"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/posts\/15104","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/users\/25"}],"replies":[{"embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/comments?post=15104"}],"version-history":[{"count":32,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/posts\/15104\/revisions"}],"predecessor-version":[{"id":15650,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/posts\/15104\/revisions\/15650"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/media\/15103"}],"wp:attachment":[{"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/media?parent=15104"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/categories?post=15104"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/tags?post=15104"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/coauthors?post=15104"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}