# 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>), [Command-line interface](<https://devfeed.tech/topics/cli.md>), [Shell](<https://devfeed.tech/topics/shell.md>), [Unix](<https://devfeed.tech/topics/unix.md>)

Tags: [command-line](<https://devfeed.tech/tags/command-line.md>), [git](<https://devfeed.tech/tags/git.md>), [programming](<https://devfeed.tech/tags/programming.md>), [shell-script](<https://devfeed.tech/tags/shell-script.md>), [unix](<https://devfeed.tech/tags/unix.md>)

## AI overview

This tutorial explains how to replace the Perl-based git-number utility with Git aliases and Unix shell commands. It demonstrates selecting files by their order in git status, adding aliases to .gitconfig, and extending the approach to several file-selection use cases.

## 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