<commit_before>---
layout: post
title: My Favorite Git Alias
date:   2013-05-11 20:00:00
---


<p>As pretty much every developer, I am lazy and try to make my life super easy. Being lazy often involves creating alias for every thing you type more than twice. And as I use git all day long, creating git aliases is a logical path.</p>
<p>One of my favorite git alias is this one:</p>
<pre>rmall = !git rm $(git ls-files -d)</pre>

<p>Everything starts with the `git rm` which removes files from the working tree and the index. So to remove a file you usually type</p>
<pre>$ git rm path/to/my/file.js</pre>
<p>But when you have a lot of files to remove and you are lazy, it can be annoying to type the name of every file. This is where the second part gets interesting.</p>

<h3>Yo dawg I heard you like git</h3>
<p>The following command</p>
<pre>$ git ls-files -d</pre>
<p>shows you the files that have been removed (-d stands for -deleted). So if you combine the two together you can remove every files that has been deleted in one command.
<br>To do this, wrap the second command in `$()`. Which gives us:</p>
<pre>$ git rm $(git ls-files -d)</pre>
<p>Boom. With one command you removed every files. But this command is way too long for my lazy fingers so let’s create an alias.</p>

<h3>Git alias</h3>
<p>Creating an alias for git is really easy. I will assume you already know how to create some, but if that’s not the case <a target="_blank" href="http://git-scm.com/book/en/Git-Basics-Tips-and-Tricks">you can learn here</a>.
<br>With this command though, there is a subtlety. Let’s try and add this to the git config file:</p>
<pre>[alias]<br> rmall = rm $(git ls-files -d)</pre>
<p>If you try to run this with `git rmall`, git will throw an error:</p>
<pre>error: unknown switch `d’</pre>
<p>All we need is to add a `!` in front of the command to tell git to run this as a command to the shell:</p>
<pre>[alias]<br> rmall = !git rm $(git ls-files -d)</pre>
<p>And you’re good to go.</p>
<p>If you’re interested in seeing others git aliases, you can <a target="_blank" href="https://github.com/romainberger/dotfiles">check out my dotfiles</a>.</p><commit_msg>Fix git post<commit_after>---
layout: post
title: My Favorite Git Alias
date:   2013-05-11 20:00:00
---


<p>As pretty much every developer, I am lazy and try to make my life super easy. Being lazy often involves creating alias for every thing you type more than twice. And as I use git all day long, creating git aliases is a logical path.</p>
<p>One of my favorite git alias is this one:</p>
{% highlight bash %}
rmall = !git rm $(git ls-files -d)
{% endhighlight %}

<p>Everything starts with the <span class="inline-code">git rm</span> which removes files from the working tree and the index. So to remove a file you usually type</p>
<pre>$ git rm path/to/my/file.js</pre>
<p>But when you have a lot of files to remove and you are lazy, it can be annoying to type the name of every file. This is where the second part gets interesting.</p>

<h3>Yo dawg I heard you like git</h3>
<p>The following command</p>
{% highlight bash %}
$ git ls-files -d
{% endhighlight %}
<p>shows you the files that have been removed (-d stands for -deleted). So if you combine the two together you can remove every files that has been deleted in one command.
<br>To do this, wrap the second command in <span class="inline-code">$()</span>. Which gives us:</p>
{% highlight bash %}
$ git rm $(git ls-files -d)
{% endhighlight %}
<p>Boom. With one command you removed every files. But this command is way too long for my lazy fingers so let’s create an alias.</p>

<h3>Git alias</h3>
<p>Creating an alias for git is really easy. I will assume you already know how to create some, but if that’s not the case <a target="_blank" href="http://git-scm.com/book/en/Git-Basics-Tips-and-Tricks">you can learn here</a>.
<br>With this command though, there is a subtlety. Let’s try and add this to the git config file:</p>
{% highlight bash %}
[alias]
    rmall = rm $(git ls-files -d)
{% endhighlight bash %}
<p>If you try to run this with <span class="inline-code">git rmall</span>, git will throw an error:</p>
<pre>error: unknown switch `d’</pre>
<p>All we need is to add a <span class="inline-code">!</span> in front of the command to tell git to run this as a command to the bash:</p>
{% highlight bash %}
[alias]
    rmall = !git rm $(git ls-files -d)
{% endhighlight %}
<p>And you’re good to go.</p>
<p>If you’re interested in seeing others git aliases, you can <a target="_blank" href="https://github.com/romainberger/dotfiles">check out my dotfiles</a>.</p>
{'fraction_non_alphanumeric': 0.12185056472632494, 'fraction_numerical': 0.007819287576020852, 'mean_word_length': 3.973002159827214, 'pattern_counts': {'":': 0, '<': 99, '<?xml version=': 0, '>': 99, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '668114', 'n_tokens_mistral': 1509, 'n_tokens_neox': 1429, 'n_words': 709}