<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:media="http://search.yahoo.com/mrss/"><channel><title><![CDATA[git - Rado's Blog]]></title><description><![CDATA[git - Rado's Blog]]></description><link>https://blog.rstankov.com/</link><image><url>http://blog.rstankov.com/favicon.png</url><title>git - Rado&apos;s Blog</title><link>https://blog.rstankov.com/</link></image><generator>Ghost 1.8</generator><lastBuildDate>Tue, 09 Jun 2026 10:59:34 GMT</lastBuildDate><atom:link href="https://blog.rstankov.com/tag/git/rss/" rel="self" type="application/rss+xml"/><ttl>60</ttl><item><title><![CDATA[Git Tricks]]></title><description><![CDATA[<div class="kg-card-markdown"><p>Couple of weeks ago I saw this <a href="https://twitter.com/mscccc/status/954098595623391233">tweet</a> from <a href="https://twitter.com/mscccc">Mike</a>:</p>
<div styles="width: 80%; margin: 0 auto">
  <a href="https://twitter.com/mscccc/status/954098595623391233" target="blank">
    <img src="https://s3.amazonaws.com/rstankov-blog/tweet_git_undo.png" width="100%">
   </a>
</div>
<p>I had similar problem couple times when dealing with <a href="https://git-scm.com/">Git</a>. So, I created the following git command:</p>
<pre><code class="language-bash">git undo
</code></pre>
<p>It is far easier to remember ?</p>
<p><a href="https://git-scm.com/">Git</a> is powerful, but its build in commands can be confusing. Pretty much everything is</p></div>]]></description><link>https://blog.rstankov.com/git-tricks/</link><guid isPermaLink="false">5a741a0dcdb89b0004851bef</guid><category><![CDATA[productivity]]></category><category><![CDATA[git]]></category><dc:creator><![CDATA[Radoslav Stankov]]></dc:creator><pubDate>Wed, 07 Feb 2018 14:56:53 GMT</pubDate><media:content url="https://images.unsplash.com/photo-1477949331575-2763034b5fb5?ixlib=rb-0.3.5&amp;q=80&amp;fm=jpg&amp;crop=entropy&amp;cs=tinysrgb&amp;w=1080&amp;fit=max&amp;ixid=eyJhcHBfaWQiOjEyNzY3fQ&amp;s=0a821ed7b2eb08c681259959356681aa" medium="image"/><content:encoded><![CDATA[<div class="kg-card-markdown"><img src="https://images.unsplash.com/photo-1477949331575-2763034b5fb5?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=1080&fit=max&ixid=eyJhcHBfaWQiOjEyNzY3fQ&s=0a821ed7b2eb08c681259959356681aa" alt="Git Tricks"><p>Couple of weeks ago I saw this <a href="https://twitter.com/mscccc/status/954098595623391233">tweet</a> from <a href="https://twitter.com/mscccc">Mike</a>:</p>
<div styles="width: 80%; margin: 0 auto">
  <a href="https://twitter.com/mscccc/status/954098595623391233" target="blank">
    <img src="https://s3.amazonaws.com/rstankov-blog/tweet_git_undo.png" width="100%" alt="Git Tricks">
   </a>
</div>
<p>I had similar problem couple times when dealing with <a href="https://git-scm.com/">Git</a>. So, I created the following git command:</p>
<pre><code class="language-bash">git undo
</code></pre>
<p>It is far easier to remember ?</p>
<p><a href="https://git-scm.com/">Git</a> is powerful, but its build in commands can be confusing. Pretty much everything is possible but sometimes is so complicated it might as well be impossible. Because of this, I have a lot of helpers for Git.</p>
<p>In Git <a href="https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration">config files</a> you can create aliases. Part of my <a href="https://github.com/RStankov/config_files/blob/master/dot/gitconfig#L12">.gitrc</a> are the following aliases:</p>
<pre><code class="language-bash">[alias]
  lol = log --graph --decorate --pretty='format:%C(yellow)%h%Cgreen%d%Creset %s %C(white) (%an, %ar)%Creset' --abbrev-commit
  undo = reset --soft HEAD^
  amend = commit --amend
</code></pre>
<ul>
<li><code>git lol</code> is just a pretty git logs</li>
<li><code>git undo</code> removes the current commits but leave the changes</li>
<li><code>git amend</code> would put your current changes into the previous commit</li>
</ul>
<p>The other way you can extend Git is to create custom git commands by creating scripts starting with <code>git-command-name</code> and put them in your load path.</p>
<p>Then you can call <code>git command</code>.</p>
<p>I have a couple of those.</p>
<p>I create Pull Requests all the time because I work with <a href="https://martinfowler.com/bliki/FeatureBranch.html">feature branches</a>. Because of this, I have <code>git pull-request</code> which pushes the current branch to <a href="https://github.com/">GitHub</a> and opens the new pull request screen.</p>
<p>Here is the <a href="https://github.com/RStankov/config_files/blob/master/bin/git-pull-request">source of the script</a>:</p>
<pre><code class="language-bash">#!/bin/bash

current_branch=`git rev-parse --abbrev-ref HEAD`
remote_url=`git remote get-url origin | awk '{gsub(/git@github.com:/,&quot;&quot;)}1' | awk '{gsub(/\.git/,&quot;&quot;)}1'`

git push  origin $current_branch --set-upstream

open https://github.com/$remote_url/compare/$current_branch?expand=1
</code></pre>
<p>While working on features, the master is changing. Keeping your feature branch up to date with the master is essential. So I have <code>git rebase-on-master</code></p>
<p>Here is the <a href="https://github.com/RStankov/config_files/blob/master/bin/git-rebase-on-master">source of the script</a>:</p>
<pre><code class="language-bash">#!/bin/bash

current_branch=`git rev-parse --abbrev-ref HEAD`
git checkout master
git pull origin master --rebase
git rebase master $current_branch
</code></pre>
<p>After I'm done with a branch, I have to remove it. So I have <code>git delete-merged</code>. It removes all merged branches compared to your current branch. It is useful when you pull a master after you have merged a feature branch</p>
<p>Here is the <a href="https://github.com/RStankov/config_files/blob/master/bin/git-delete-merged">source of the script</a>:</p>
<pre><code class="language-bash">#!/bin/bash
git branch --merged | grep -v &quot;\*&quot; | xargs -n 1 git branch -d
</code></pre>
<p>Those are some of the most significant productivity boosters, I have to deal with Git. I have couple more tricks you can find in my <a href="https://github.com/RStankov/config_files">config files</a>.</p>
</div>]]></content:encoded></item></channel></rss>