# Simplify & replace git-number with git aliases

DevFeed: [Simplify & replace git-number with git aliases](<https://devfeed.tech/articles/simplify-replace-git-number-with-git-aliases-25251.md>)

Original publisher: [Read original article](<https://kau.sh/blog/git-alias/>)

Author: Kaushik Gopal

Published: 2024-01-27T20:00:00Z

Content type: tutorial

Language: en

Sources: [Kaushik Gopal's Site](<https://devfeed.tech/sources/kaushik-gopal-s-site.md>)

Topics: [Git](<https://devfeed.tech/topics/git.md>), [Shell](<https://devfeed.tech/topics/shell.md>), [Perl](<https://devfeed.tech/topics/perl.md>)

Tags: [aliases](<https://devfeed.tech/tags/aliases.md>), [dependencies](<https://devfeed.tech/tags/dependencies.md>), [git](<https://devfeed.tech/tags/git.md>), [git-aliases](<https://devfeed.tech/tags/git-aliases.md>), [perl](<https://devfeed.tech/tags/perl.md>), [shell](<https://devfeed.tech/tags/shell.md>), [simplify](<https://devfeed.tech/tags/simplify.md>), [unix](<https://devfeed.tech/tags/unix.md>)

## AI overview

The author replaces git-number, a Perl tool they considered more than their use required, with Git aliases to avoid installing an extra dependency. A simple `git add` alias uses `git status --porcelain` and shell text processing to select a file by its position in the status list. The author says a later, more complex alias also handles adding all files with no argument or `.`, and selecting numbered ranges such as files 2-3 or 3-5. They favor keeping the working command in `.gitconfig` rather than maintaining a separate script. The excerpt does not include the complete final alias or all command details.

## Source excerpt

I wrote a blog post about git-number and how useful it was for my command line git usage. In an on-going effort to simplify my lifestyle & setup, I replaced git-number with a few git aliases. I'll explain how I recreated the functionality in this blog post. Why replace it? ## Looking at git-number's source I realize it is written in Perl. I'm not here to cast judgement on another programming language but reading the code, it felt like overkill for my use cases. It also meant I could eliminate one additional 3rd party library that I have to install every time. Let's go ahead and recreate it with some good old unix command line fu. Building git add <number> # To git add the first file, I have to manually type the entire path git add 0.collapse-categories-into.... This is tedious and error-prone. If your file is nested in a series of directories (like an Android or iOS app), it becomes worse. With git-number, this is as simple as git-number add 1 # where 1 stands for the order # in which a file shows up in git status Let's recreate that with a git alias. # in your .gitconfig file [alias] a = !"a() { <UNIX COMMAND GOES HERE> ; }; a" The key now is to come up with a unix command that will take in a number and pluck that file for you. Here's a simple version of that command: You can now make it a git alias by adding it to your .gitconfig file: # .gitconfig [alias] a = !"a() { git add $(git status --porcelain | cut -b4- | sed -n \"$1p;$1q\"); }; a" You can systematically recreate all of the git-number functionality in pure git aliases! Bonus tweaks # Over time, I've tweaked the above command to a behemoth shell command that accounts for a variety of use cases: g a - git add all files g a . - git add all files g a 2-3 - git add second and third file g a 3-5 - git add second to fifth file Here's what my actual alias is, in all its glory: # .gitconfig [alias] a = "!f() { \ if [[ $# -eq 0 || \"$1\" == \".\" ]]; then \ git add .; \ else \ files_to_add=(); \ for arg in $(seq $(g