<?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: Alan McKenna</title>
    <description>The latest articles on DEV Community by Alan McKenna (@alanmckenna).</description>
    <link>https://dev.to/alanmckenna</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%2F705078%2Fc267fd04-d6d7-4154-8a60-cd9f794acdff.jpeg</url>
      <title>DEV Community: Alan McKenna</title>
      <link>https://dev.to/alanmckenna</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/alanmckenna"/>
    <language>en</language>
    <item>
      <title>Git: Learn Interactive Commands</title>
      <dc:creator>Alan McKenna</dc:creator>
      <pubDate>Wed, 15 Sep 2021 13:50:26 +0000</pubDate>
      <link>https://dev.to/alanmckenna/git-learn-interactive-commands-53b2</link>
      <guid>https://dev.to/alanmckenna/git-learn-interactive-commands-53b2</guid>
      <description>&lt;p&gt;You probably started out using Git in the command line. That's great! But unfortunately it's common, and understandable, for people to then move straight to a GUI version of Git, such as one of the many VSCode Git extensions.&lt;/p&gt;

&lt;p&gt;I did something similar when I first started collaborating with Git, but if I had just stuck it out with the command line I would've learned much more rapidly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Use Command Line?
&lt;/h2&gt;

&lt;h6&gt;
  
  
  &lt;em&gt;First Principles&lt;/em&gt;
&lt;/h6&gt;

&lt;p&gt;Okay, I'm not saying Git GUIs are bad, they're the opposite in fact. I use them all the time nowadays for certain tasks, mainly visualising complex tree structures.&lt;/p&gt;

&lt;p&gt;What I am saying is, &lt;em&gt;&lt;strong&gt;if&lt;/strong&gt;&lt;/em&gt; you're wanting to get the most out of Git and fully understand it, you should learn it through the command line first.&lt;/p&gt;

&lt;h3&gt;
  
  
  Interactive Add
&lt;/h3&gt;

&lt;h6&gt;
  
  
  &lt;em&gt;Clean Up Your Commits&lt;/em&gt;
&lt;/h6&gt;

&lt;p&gt;This is really useful when I've been writing a feature and I've maybe also updated other things along the way that I don't want to include in the same commit e.g. fixing tests, refactoring other classes etc.&lt;/p&gt;

&lt;p&gt;This allows you to see the state of all changes and provides all the options you can use.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git add &lt;span class="nt"&gt;-i&lt;/span&gt;
           staged     unstaged path
  1:    unchanged        +2/-0 README.md

&lt;span class="k"&gt;***&lt;/span&gt; Commands &lt;span class="k"&gt;***&lt;/span&gt;
  1: status   2: update   3: revert   4: add untracked
  5: patch    6: diff     7: quit     8: &lt;span class="nb"&gt;help
&lt;/span&gt;What now&amp;gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can then selectively stage specific files using the add or patch option options.&lt;/p&gt;

&lt;p&gt;The add option stages all changes in the file, the patch option goes through all the different hunks (changes grouped together) within the file and allows you to optionally stage each hunk.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;           staged     unstaged path
  1:    unchanged        +2/-0 README.md
Patch update&amp;gt;&amp;gt; 1
           staged     unstaged path
&lt;span class="k"&gt;*&lt;/span&gt; 1:    unchanged        +2/-0 README.md
Patch update&amp;gt;&amp;gt; 
diff &lt;span class="nt"&gt;--git&lt;/span&gt; a/README.md b/README.md
index 48bee75..6056e4a 100644
&lt;span class="nt"&gt;---&lt;/span&gt; a/README.md
+++ b/README.md
@@ &lt;span class="nt"&gt;-20&lt;/span&gt;,3 +20,5 @@ &lt;span class="nv"&gt;$ &lt;/span&gt;login &lt;span class="nt"&gt;--store&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;https://dev-mimir.com
 &lt;span class="nv"&gt;$ &lt;/span&gt;populate products
 &lt;span class="nv"&gt;$ &lt;/span&gt;node serve
+
+some change
&lt;span class="o"&gt;(&lt;/span&gt;1/1&lt;span class="o"&gt;)&lt;/span&gt; Stage this hunk &lt;span class="o"&gt;[&lt;/span&gt;y,n,q,a,d,e,?]?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Interactive Rebase
&lt;/h3&gt;

&lt;h6&gt;
  
  
  &lt;em&gt;Clean Up Your Branch&lt;/em&gt;
&lt;/h6&gt;

&lt;p&gt;Okay this is my favourite Git command, it's saved my bacon more times than I can remember now. When in doubt, interactive rebase. &lt;/p&gt;

&lt;p&gt;So when I'm working on my local branch I tend to make a lot of messy commits, sometimes they'll be in an order that don't really make sense that might cause issues down the line if we ever want to rollback, they include things that they really shouldn't, they're poorly described etc.&lt;/p&gt;

&lt;p&gt;Before I push up to my remote branch I usually have to do an interactive rebase to clean up my branch.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git rebase &lt;span class="nt"&gt;-i&lt;/span&gt; HEAD~4
 pick a204433 refactor: rename TicketBoard
 pick 72ceae8 refactor: generic support tickets table
 pick ba2925d refactor: organise React folder components/services
 pick 95023db feat&lt;span class="o"&gt;(&lt;/span&gt;wip&lt;span class="o"&gt;)&lt;/span&gt;: added TicketBoard placeholder services

 &lt;span class="c"&gt;# Rebase 9c24617..95023db onto 95023db (4 commands)&lt;/span&gt;
 &lt;span class="c"&gt;#&lt;/span&gt;
 &lt;span class="c"&gt;# Commands:&lt;/span&gt;
 &lt;span class="c"&gt;# p, pick &amp;lt;commit&amp;gt; = use commit&lt;/span&gt;
 &lt;span class="c"&gt;# r, reword &amp;lt;commit&amp;gt; = use commit, but edit the commit message&lt;/span&gt;
 &lt;span class="c"&gt;# e, edit &amp;lt;commit&amp;gt; = use commit, but stop for amending&lt;/span&gt;
 &lt;span class="c"&gt;# s, squash &amp;lt;commit&amp;gt; = use commit, but meld into previous commit&lt;/span&gt;
 &lt;span class="c"&gt;# f, fixup &amp;lt;commit&amp;gt; = like "squash", but discard this commit's log message&lt;/span&gt;
 &lt;span class="c"&gt;# x, exec &amp;lt;command&amp;gt; = run command (the rest of the line) using shell&lt;/span&gt;
 &lt;span class="c"&gt;# b, break = stop here (continue rebase later with 'git rebase --continue')&lt;/span&gt;
 &lt;span class="c"&gt;# d, drop &amp;lt;commit&amp;gt; = remove commit&lt;/span&gt;
 &lt;span class="c"&gt;# l, label &amp;lt;label&amp;gt; = label current HEAD with a name&lt;/span&gt;
 &lt;span class="c"&gt;# t, reset &amp;lt;label&amp;gt; = reset HEAD to a label&lt;/span&gt;
 &lt;span class="c"&gt;# m, merge [-C &amp;lt;commit&amp;gt; | -c &amp;lt;commit&amp;gt;] &amp;lt;label&amp;gt; [# &amp;lt;oneline&amp;gt;]&lt;/span&gt;
 &lt;span class="c"&gt;# .       create a merge commit using the original merge commit's&lt;/span&gt;
 &lt;span class="c"&gt;# .       message (or the oneline, if no original merge commit was&lt;/span&gt;
 &lt;span class="c"&gt;# .       specified). Use -c &amp;lt;commit&amp;gt; to reword the commit message.&lt;/span&gt;
 &lt;span class="c"&gt;#&lt;/span&gt;
 &lt;span class="c"&gt;# These lines can be re-ordered; they are executed from top to bottom.&lt;/span&gt;
 &lt;span class="c"&gt;#&lt;/span&gt;
 &lt;span class="c"&gt;# If you remove a line here THAT COMMIT WILL BE LOST.&lt;/span&gt;
 &lt;span class="c"&gt;#&lt;/span&gt;
 &lt;span class="c"&gt;# However, if you remove everything, the rebase will be aborted.&lt;/span&gt;
 &lt;span class="c"&gt;#&lt;/span&gt;
 &lt;span class="c"&gt;# Note that empty commits are commented out&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Look at all the helpful documentation that you're given with this command, you practically don't even need to remember what anything does because it's all right there. &lt;/p&gt;

&lt;p&gt;So, if I wanted to squash the first and last two commits together, that's easy to do. I just need to follow the docs and re-order the commits and change from &lt;code&gt;pick&lt;/code&gt; to &lt;code&gt;squash&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git rebase &lt;span class="nt"&gt;-i&lt;/span&gt; HEAD~4
 pick ba2925d refactor: organise React folder components/services
 pick 95023db feat&lt;span class="o"&gt;(&lt;/span&gt;wip&lt;span class="o"&gt;)&lt;/span&gt;: added TicketBoard placeholder services
 squash a204433 refactor: rename TicketBoard
 squash 72ceae8 refactor: generic support tickets table
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;I hope this post has highlighted that you don't need much to get a lot out of Git. Just these few commands can give you a lot of flexibility and control, which is often something that I find lacking in some Git GUIs. &lt;/p&gt;

</description>
      <category>git</category>
    </item>
    <item>
      <title>Git: Commit Messages</title>
      <dc:creator>Alan McKenna</dc:creator>
      <pubDate>Tue, 14 Sep 2021 12:38:31 +0000</pubDate>
      <link>https://dev.to/alanmckenna/git-commit-messages-3ibe</link>
      <guid>https://dev.to/alanmckenna/git-commit-messages-3ibe</guid>
      <description>&lt;p&gt;When I first started out with Git I was told I could save time by just using the &lt;a href="https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---messageltmsggt"&gt;-m&lt;/a&gt; flag to write the commit message at the same time. "Amazing!" I thought, "I've just saved 2 seconds. 10x Dev here I come"&lt;/p&gt;




&lt;h2&gt;
  
  
  Context is King
&lt;/h2&gt;

&lt;p&gt;Now I realise that I was missing the opportunity to add valuable context to my commit messages. This extra context makes it easier to understand what's changed and why, which has two main advantages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;You don't have to rely on memory&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Your team don't have to rely on your memory&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Imagine there is an issue with the number of active Gatling users, so you want to work out why the active users were changed. What commit message is clearer?&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Gatling active users fixed&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Or this?&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;fix(load-test): Gatling active users&lt;/p&gt;

&lt;p&gt;This change seeks to fix the active user and request rate currently in place for load-test.&lt;/p&gt;

&lt;p&gt;Removing the ObtainAccessTokenDuringTest scenario from the simulation flattens the active users during test, as this was not working as intended.&lt;/p&gt;

&lt;p&gt;Additionally the access token should live for 60 minutes, eliminating the need for obtaining a new one during load tests &amp;lt; 60 minutes.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The first commit message only tells you &lt;em&gt;what&lt;/em&gt; has changed, which really should be obvious from your code change anyway. &lt;/p&gt;

&lt;p&gt;Whereas the second commit message tells you &lt;em&gt;what&lt;/em&gt; &amp;amp; &lt;em&gt;why&lt;/em&gt;. The &lt;em&gt;why&lt;/em&gt; is the context and is not always obvious from the code change.&lt;/p&gt;

&lt;p&gt;I like to follow the rule of concise commit message headers and detailed descriptions. People should be able to glance at it and have a rough idea of what it is about without going into the full description. But importantly the detail is there if required.&lt;/p&gt;




&lt;h2&gt;
  
  
  Following Standards
&lt;/h2&gt;

&lt;p&gt;You can take this a step further by also working to a commit message standard in your team/organisation. An example that I use is a variation of &lt;a href="https://www.conventionalcommits.org/en/v1.0.0/"&gt;Conventional Commits&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;With this standard in place you can also then use Git Hooks to automatically validate your commit messages, or use something like the GitHub Action &lt;a href="https://github.com/ahmadnassri/action-commit-lint"&gt;action-commit-lint&lt;/a&gt; to do this.&lt;/p&gt;




&lt;h3&gt;
  
  
  Why?
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;A shared understanding of what a &lt;em&gt;good&lt;/em&gt; commit message should looks like&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A shared understanding is great because that makes reviewing other people's Pull Requests (PRs) much easier. Additionally it makes it easier to help others improve their commits during review by having something to point to.&lt;/p&gt;

&lt;p&gt;PRs are not just about reviewing source code, the commit messages are also important for the reasons I mentioned previously.&lt;/p&gt;




&lt;blockquote&gt;
&lt;p&gt;Automate Changelogs&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;One of the biggest benefits I've found with following a standard is that it allows you to automate Changelog creation. This helps to reduce the number of tasks required for the person doing the release and makes sure the Changelog is always the same format.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Features&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;feat: some cool feature&lt;/li&gt;
&lt;li&gt;!feat: this is a breaking change&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Fixes&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;fix(api): fix some bug&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Other&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;refactor: make class more readable &lt;/li&gt;
&lt;li&gt;chore(deps): bump X version&lt;/li&gt;
&lt;li&gt;docs: improve README.md&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Yes, commit messages aren't the most sexy topic in software engineering, but I think they are an overlooked and important aspect of healthy collaboration. &lt;/p&gt;

&lt;p&gt;Half of our job is reviewing other people's code, and I always have much more respect for that person if they have clean and well described commits. It's one of the differences between a Junior and a Senior. &lt;/p&gt;

&lt;p&gt;If your team doesn't already follow a commit standard then why not suggest it and implement validation? It's such an easy change and can really improve your code health.&lt;/p&gt;

</description>
      <category>git</category>
      <category>codereview</category>
    </item>
  </channel>
</rss>
