<?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: Fausto NA</title>
    <description>The latest articles on DEV Community by Fausto NA (@brainlessdeveloper).</description>
    <link>https://dev.to/brainlessdeveloper</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%2F15673%2Fafff85e7-ba53-4879-baa0-022c6b960278.jpeg</url>
      <title>DEV Community: Fausto NA</title>
      <link>https://dev.to/brainlessdeveloper</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/brainlessdeveloper"/>
    <language>en</language>
    <item>
      <title>Git rich or die tryin' 01: Ideas from our Git setups</title>
      <dc:creator>Fausto NA</dc:creator>
      <pubDate>Fri, 07 Apr 2017 14:09:57 +0000</pubDate>
      <link>https://dev.to/brainlessdeveloper/git-rich-or-die-tryin-01-ideas-from-our-git-setups</link>
      <guid>https://dev.to/brainlessdeveloper/git-rich-or-die-tryin-01-ideas-from-our-git-setups</guid>
      <description>&lt;p&gt;This post is part of a series about our Git setups. In this series we will focus on the Git aliases we use the most, particularly the ones we find interesting (i.e., not &lt;code&gt;c = commit&lt;/code&gt;) and that have increased our productivity using Git.&lt;/p&gt;

&lt;p&gt;A complete compilation can be found &lt;a href="https://tech.store2be.com/never-forgit/"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Rebasing
&lt;/h1&gt;

&lt;p&gt;For the following aliases we're going to define shell functions inside of an alias and call them directly afterwards.&lt;/p&gt;

&lt;h2&gt;
  
  
  rbb
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rbb = "!f() { git rebase -i HEAD~$1; }; f"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Interactive rebase by the amount of commits passed through the first argument. Using &lt;code&gt;git rbb 3&lt;/code&gt; in a project with at least three commits will leave you in your editor of choice with something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--37TB5KZQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/kne1sylg1kis0b9c2pyt.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--37TB5KZQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/kne1sylg1kis0b9c2pyt.jpg" alt="interactive rebase alias"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  cfix
&lt;/h2&gt;

&lt;p&gt;We can also use backticks surrounding a command to evaluate with the shell and pass the results as a part of our git alias. We use this with &lt;code&gt;rev-parse&lt;/code&gt; in the following alias:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cfix = "!f() { git commit --fixup `git rev-parse --short HEAD` &amp;amp;&amp;amp; git rebase -i HEAD~2 -i --autosquash; }; f"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We use &lt;code&gt;cfix&lt;/code&gt; when the following situation arises. Say you've committed something with the message &lt;code&gt;Fix the terrible bug&lt;/code&gt; only to find out that the fix did not actually work the way you expected. So you make your changes and go:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git add .&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now you commit the new, real fix:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git commit -m "Fix the terrible bug... again"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Wouldn't it be nice to just have the new changes added to the last commit? Well, you can do that with a &lt;code&gt;rebase&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git rebase -i HEAD~2&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This will leave you with your editor looking like the first image in this section. Then you can change the &lt;code&gt;pick {COMMIT HASH} Fix the terrible bug... again&lt;/code&gt; line to &lt;code&gt;fixup {COMMIT HASH} Fix the terrible bug... again&lt;/code&gt; and save the file, with the desired results.&lt;/p&gt;

&lt;p&gt;You can do exactly the same but avoiding the numerous commands by using &lt;code&gt;cfix&lt;/code&gt;. Here's an example screen after adding changes and running &lt;code&gt;git cfix&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LGD1fhN0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/r3izk440e546qayeimta.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LGD1fhN0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/r3izk440e546qayeimta.jpg" alt="use latest add as a fixup for last commit"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A similar result can be achieved using &lt;code&gt;git commit --amend&lt;/code&gt;, but with &lt;code&gt;cfix&lt;/code&gt; you can also &lt;code&gt;squash&lt;/code&gt;, or even use the commit, and/or &lt;code&gt;reword&lt;/code&gt; the previous one. Some people, however, don't recommend rewriting Git history. You might want to read up on the topic starting with posts like the ancient &lt;a href="http://paul.stadig.name/2010/12/thou-shalt-not-lie-git-rebase-ammend.html"&gt;Thou Shalt Not Lie: git rebase, amend, squash, and other lies&lt;/a&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Logging
&lt;/h1&gt;

&lt;p&gt;There are many different options when it comes to customizing &lt;code&gt;git log&lt;/code&gt;. Some of the most common options are passed using flags like &lt;code&gt;--graph&lt;/code&gt; or &lt;code&gt;--decorate&lt;/code&gt;, but the main differentiator is &lt;code&gt;--pretty&lt;/code&gt;. Here are some of ours, with screenshots to showcase them:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xc4bXux---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/mfmcdm8wrner4yasrjsu.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xc4bXux---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/mfmcdm8wrner4yasrjsu.jpg" alt="pretty git log alias"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;--pretty=format:'%h %ad | %s%d [%an]'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yIptypLa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/gj1vbtzlb7alajxw1dri.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yIptypLa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/gj1vbtzlb7alajxw1dri.jpg" alt="pretty git log alias"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;--pretty=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(auto)%d%C(reset)'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Extensive documentation on how to build your own &lt;code&gt;--pretty&lt;/code&gt; line can be found &lt;a href="https://git-scm.com/docs/pretty-formats"&gt;here&lt;/a&gt;. An example of a finished &lt;code&gt;git log&lt;/code&gt; alias could be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;lg = git log --graph --abbrev-commit --decorate --pretty=format:'%h %ad | %s%d [%an]'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Pull requests
&lt;/h1&gt;

&lt;p&gt;If you've installed the &lt;code&gt;hub&lt;/code&gt; CLI (&lt;a href="https://tech.store2be.com/cli/linux/hub/2017/03/28/installing-the-hub-cli-on-linux/"&gt;and here's how to do that&lt;/a&gt;), you can add the following alias to your toolbelt:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pr = !hub pull-request
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In case you're wondering, that &lt;code&gt;!&lt;/code&gt; at the start of the alias tells git that the command has to be run by the shell.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Hi there, we’re &lt;a href="https://www.store2be.com"&gt;store2be&lt;/a&gt;, a Berlin based startup that builds a SaaS enabled marketplace for short term retails space. If you like what we are posting you might wanna check out &lt;a href="https://tech.store2be.com"&gt;the store2be tech page&lt;/a&gt; or follow our &lt;a href="https://medium.com/store2be-tech"&gt;Medium channel&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>cli</category>
      <category>git</category>
      <category>alias</category>
    </item>
  </channel>
</rss>
