{"id":272,"date":"2019-03-27T11:13:13","date_gmt":"2019-03-27T16:13:13","guid":{"rendered":"http:\/\/myblog.vindaloo.com\/?p=272"},"modified":"2019-03-27T11:20:25","modified_gmt":"2019-03-27T16:20:25","slug":"getting-out-of-git-hell-easily","status":"publish","type":"post","link":"http:\/\/myblog.vindaloo.com\/?p=272","title":{"rendered":"Getting out of git hell easily"},"content":{"rendered":"<p>Everyone has war stories about git. They almost always involve letting a feature\/topic branch get far out of date from the feature branch&#8217;s parent. My friend Sebastian has actually figured out a quick way to get out of what I call <em>git hell<\/em>.The best way to avoid that situation is incorporate <strong>git rebase<\/strong>\u00a0and <strong>git rebase -i<\/strong>\u00a0into your normal workflow. Basically, use git rebase periodically and right before you submit your merge request to make sure that your branch will cleanly play onto it&#8217;s parent integration branch. And use git rebase -i and git push &#8211;force if you need it, on your topic branch to keep a concise commit history as you build your topic deltas.<\/p>\n<p>No matter what happens, you or someone on your team will end up in git hell where you are replaying a stack of commits so you can generate a clean commit history and publish your deltas. If you end up there, you need to understand that git merge is actually your friend. Sebastian suggests the following:<\/p>\n<pre><code>## Be safe, do this work on a test branch.\r\n\r\ngit checkout topic\/branch\r\ngit checkout -b test-topic\/branch\r\n\r\n## Make sure the local copy of master is up-to-date.\r\ngit checkout master\r\ngit pull master\r\n\r\n## Go back to your test branch and merge in master.\r\n\r\ngit checkout test-topic\/branch\r\ngit merge master\r\n\r\n## Reset your state to be that of master. This leaves your changes as \r\n## an unstaged blob against master.\r\n\r\ngit reset master<\/code><\/pre>\n<p>At this point your working directory should have all the changes from your topic branch unstaged against the HEAD of master<\/p>\n<pre><code>git diff<\/code><\/pre>\n<p>should confirm this. Now you can add what you want and write a new commit that performs the changes that you want comfortable in the knowledge that you aren&#8217;t undoing upstream changes. You&#8217;ll use <code>git add<\/code> and <code>git commit<\/code> to accomplish this. The difference is that your new set of change should apply cleanly to master. From here you can:<\/p>\n<pre><code>## When you are comfortable that you your test branch captures your\r\n## deltas.\r\n\r\ngit checkout test-topic\/branch\r\ngit branch -D topic\/branch\r\ngit checkout -b topic\/branch\r\ngit push --force\r\ngit\u00a0branch\u00a0-D\u00a0test-topic\/branch<\/code><\/pre>\n<p>Sebastian says &#8220;Have fun!&#8221;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Everyone has war stories about git. They almost always involve letting a feature\/topic branch get far out of date from the feature branch&#8217;s parent. My friend Sebastian has actually figured out a quick way to get out of what I call git hell.The best way to avoid that situation is incorporate git rebase\u00a0and git rebase &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/myblog.vindaloo.com\/?p=272\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Getting out of git hell easily&#8221;<\/span><\/a><\/p>\n","protected":false},"author":54,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-272","post","type-post","status-publish","format-standard","hentry","category-open-source"],"_links":{"self":[{"href":"http:\/\/myblog.vindaloo.com\/index.php?rest_route=\/wp\/v2\/posts\/272","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/myblog.vindaloo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/myblog.vindaloo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/myblog.vindaloo.com\/index.php?rest_route=\/wp\/v2\/users\/54"}],"replies":[{"embeddable":true,"href":"http:\/\/myblog.vindaloo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=272"}],"version-history":[{"count":2,"href":"http:\/\/myblog.vindaloo.com\/index.php?rest_route=\/wp\/v2\/posts\/272\/revisions"}],"predecessor-version":[{"id":274,"href":"http:\/\/myblog.vindaloo.com\/index.php?rest_route=\/wp\/v2\/posts\/272\/revisions\/274"}],"wp:attachment":[{"href":"http:\/\/myblog.vindaloo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=272"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/myblog.vindaloo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=272"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/myblog.vindaloo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=272"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}