← Back to Blog Index

Replace the gs Alias in Ubuntu

January 16, 2021

This post was originally going to be called “Remove the gs alias in Ubuntu” but, as it transpires, removing it is actually super difficult so it’s easier to just replace it. So, what to replace it to? Luckily, as of git 2.23, there is a new git switch command, with docs here.

Essentially, git switch is for switching between branches, lifting a bit of the heavy load that git checkout carries.

How to Replace the Alias

Now, how to replace the existing gs alias? With great ease, thankfully. I use (and recommend) oh_my_zsh but similar steps are available for bash, etc. Firstly, as per my previous post on getting the current DateTime, I need to open my alias file.

nano $ZSH/plugins/common-aliases/common-aliases.plugin.zsh

Towards the bottom I have:

[...]
# Custom

alias current_time="date --utc +%FT%T.%3NZ"

To which I simply add:

[...]
# Custom

alias current_time="date --utc +%FT%T.%3NZ"
alias gs

Reload the terminal and it works!

Reasons to Change the Alias

To admit to my ignorance, I don’t know what GhostScript is, have never used it and don’t know why I’d use it. Given that I’ve never wanted to open it, having it aliased seems silly. That accidentally opening it feels like six-hour round-trip to load and then close it is reason enough to get rid.

In particular, however, I have gss aliased for git status -s, which is one of my most used aliases. Due to the brilliant piece of trolling that was the placement of the s key on the pinky of the left hand (because a) it’s the weakest finger of the generally weaker hand and b) it’s one of the most popular characters for typing), I often typo gss as gs.

After implementing my new alias, if I accidentally typo gs outside of a repo, it throws a harmless error:

➜  ~ gs
fatal: not a git repository (or any of the parent directories): .git
# Ignore that it says `fatal`, it is harmless to us in that it doesn't have any other side effects bar this message

If I am in a repo, typing gs without parameters also throws a harmless error:

➜  test-repo git:(develop) gs
fatal: missing branch or commit argument

# Again, harmless despite the `fatal` label.
# No side effects.

➜  test-repo git:(develop) gs master
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.

# Working as expected, neat!

➜  test-repo git:(master) gs develop
Switched to branch 'develop'
Your branch is up-to-date with 'origin/develop'.

# Working as expected again.

➜  test-repo git:(develop) gs
fatal: missing branch or commit argument

# Harmless error rather than unexpected behaviour
# where it may "switch" to the last branch

Efstathios Stivaros

I am Efstathios Stivaros, a full-stack developer (predominantly Ruby on Rails) from London.

Find me online

© Efstathios Stivaros 2024, Built with Gatsby