# Mining your CLI history for good git aliases

DevFeed: [Mining your CLI history for good git aliases](<https://devfeed.tech/articles/mining-your-cli-history-for-good-git-aliases-19058.md>)

Original publisher: [Read original article](<https://httptoolkit.com/blog/find-best-git-aliases/>)

Author: HTTP Toolkit; Tim Perry

Published: 2020-11-30T13:35:00Z

Content type: tutorial

Language: en

Sources: [HTTP Toolkit](<https://devfeed.tech/sources/http-toolkit.md>)

Topics: [Command-line interface](<https://devfeed.tech/topics/cli.md>), [Git](<https://devfeed.tech/topics/git.md>), [Shell](<https://devfeed.tech/topics/shell.md>), [Scripting, bash](<https://devfeed.tech/topics/scripting-bash.md>), [coding](<https://devfeed.tech/topics/coding.md>)

Tags: [bash](<https://devfeed.tech/tags/bash.md>), [cli](<https://devfeed.tech/tags/cli.md>), [command-line](<https://devfeed.tech/tags/command-line.md>), [commands](<https://devfeed.tech/tags/commands.md>), [git](<https://devfeed.tech/tags/git.md>), [git-commit](<https://devfeed.tech/tags/git-commit.md>), [master](<https://devfeed.tech/tags/master.md>)

## AI overview

This tutorial shows how to analyze shell history to identify frequently used Git commands and choose useful Git aliases. It demonstrates filtering, sorting, counting repeated commands, and grouping command prefixes to account for variable arguments.

## Source excerpt

If you use the command-line all day, CLI improvements can add a huge boost to your workflow. One of the simplest ways to improve things is to make your most used commands easier & faster to type, by creating aliases. But which aliases? Which commands are most important for your usage? You can probably guess a couple, but it's hard to know for sure, and there's plenty you'll miss. Fortunately your CLI history already has all the answers, if you just know how to ask. As a software developer I'm going to focus on git aliases here, but this applies equally well to any command-line tools you use heavily. I'm also assuming a bash-compatible shell, but the same concept should translate elsewhere easily enough. The first step is to use history to do some digging and find out what commands you run most frequently. history prints every line you've run recently in your shell, in chronological order. That gives us the data we need, and with a little bash-fu we can start to get some answers. First, what're your most run git commands? history -n | grep git | sort | uniq -c | sort -k1,1nr -k2 That takes your history, filters for git commands, sorts them alphabetically, counts the repeated lines, and then sorts by the repeat count. You can add a | head -n X too, if you'd like to see just the top X results. For me, with a few weeks history on a new laptop, that looks like: 543 git status 272 git add -p 214 git tree 71 git diff 55 git commit --amend 53 git push origin master 32 git checkout -p 30 git reset 27 git stash pop 26 git stash That tells you a bunch about my git workflow already! These are all common commands I'm using frequently, and commands I should very seriously consider aliasing. It doesn't tell the whole story though. How come git commit --amend is so high up, but git commit doesn't appear at all? That's because for many commits I run git commit -m "..." to commit and pass a message inline, so each of those commands is treated as unique, and won't appear in this top l