<?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: kakty3</title>
    <description>The latest articles on DEV Community by kakty3 (@kakty3).</description>
    <link>https://dev.to/kakty3</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%2F23612%2F823def3b-2200-43ca-9a43-bc1be9fd6c69.jpeg</url>
      <title>DEV Community: kakty3</title>
      <link>https://dev.to/kakty3</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kakty3"/>
    <language>en</language>
    <item>
      <title>Easily get current branch name in git</title>
      <dc:creator>kakty3</dc:creator>
      <pubDate>Thu, 06 Jul 2017 17:13:58 +0000</pubDate>
      <link>https://dev.to/kakty3/easy-get-current-git-branch</link>
      <guid>https://dev.to/kakty3/easy-get-current-git-branch</guid>
      <description>&lt;p&gt;Sometimes I miss the features from &lt;a href="https://www.mercurial-scm.org/"&gt;Mercurial&lt;/a&gt; which Git does not have. One of them is &lt;a href="https://www.mercurial-scm.org/repo/hg/help/outgoing"&gt;hg outgoing&lt;/a&gt; which "Show changesets not found in the specified destination repository or the default push location". Similar behavior could be achieved with &lt;code&gt;git log branchA..branchB&lt;/code&gt;, e.g to see &lt;em&gt;outgoing&lt;/em&gt; commits: &lt;code&gt;git log origin/master..feature-branch&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;One day I used that command for the branch with really long name. I just typed a few fisrt letters, pressed &lt;em&gt;tab&lt;/em&gt; and branch name was auto-completed (I personally prefer &lt;strong&gt;fish&lt;/strong&gt; shell, but it should also work for all other modern shells). I asked myself: "What if I am using &lt;strong&gt;bash&lt;/strong&gt; and I don't have the auto-completion, but I also don't want to use &lt;code&gt;git branch&lt;/code&gt; and copy-and-paste branch name?".&lt;/p&gt;

&lt;p&gt;The answer is to use &lt;code&gt;git rev-parse --abbrev-ref HEAD&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="o"&gt;&amp;gt;&lt;/span&gt; git rev-parse &lt;span class="nt"&gt;--abbrev-ref&lt;/span&gt; HEAD
feature-branch
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I've created the alias for it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git config --global alias.cb 'rev-parse --abbrev-ref HEAD'

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;where &lt;em&gt;cb&lt;/em&gt; stands for &lt;em&gt;current branch&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Now I can do following&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git log origin/master..&lt;span class="si"&gt;$(&lt;/span&gt;git cb&lt;span class="si"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Suddenly I found out that passing &lt;em&gt;remote-branch&lt;/em&gt; is not needed and previous command could be simplified:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git log origin/master..
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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