As we work a lot with Linux and UNIX systems at e.GO Mobile, terminal programs such as bash and zsh are one of our main tools.

As we often repeat many of our commands in everyday life (especially Docker or git), I would like to introduce my personal short commands in the form of aliases in this article, which may serve as a small inspiration for creating your own.

About aliases

In Linux and UNIX systems like MacOS, an alias is a short name or abbreviation that represents a longer command or sequence of commands. It is essentially a shortcut that allows users to execute complex or frequently used commands with a single word or phrase. Aliases are particularly useful for those who work with the command line interface, as they can save time and reduce the likelihood of typing errors. For example, instead of typing out a long command to update the system package manager, a user could create an alias called “update” that executes the command with a single word.

Update your ~/.bashrc or ~/.zshrc file with a new line like this to setup a new alias:

alias k='kubectl'

Keep in mind to reopen your terminal window to have an updated environment!

My aliases

Git

Even if three letters, which are necessary to execute git, are not much, you can, similar to kubectl, limit oneself to the letter g:

alias g=git

After this you should be able to run things like this:

# same as 'git chechkout master'
g chechkout master

To get up-to-date data from remote git repository, I often have to use git-fetch.

For this I have setup

alias g-fetch='git fetch --all'

to fetch all meta information for all saved remotes with a simple g-fetch.

Another topic is the synchronization of remote and local repositories.

For this purpose, I have defined the following 3 aliases that I regularly use:

# first do a `g-fetch` before iterating over all remotes
# and pull from all of them into current branch
alias g-pull='g-fetch && git remote | xargs -L1 -I R git pull R "$(git symbolic-ref --short HEAD)"'

# push current branch to all remotes
alias g-push='git remote | xargs -L1 -I R git push R "$(git symbolic-ref --short HEAD)"'

# first pull and then push
alias g-sync='g-pull && g-push'

A last thing I want to talk about in this section is, that it is a good practise to work with different stages in a development life-cycle.

That means you should have one branch for every stage you use:

  • main: Production
  • test: Testing / Beta phase
  • dev: Development / Alpha / Experimentation phase

In this example you would start developing features in dev.

Are these features ready for testing, you would merge it into test.

If the testers give “green light” for release, you will merge test to main in the last step of this cycle / sprint.

Now, if you want to switch between these quickly, without your fingers falling off, there is the possibility to define shortcuts like these:

# try to switch to `main` and if `main` is not
# existing try switching to `master`
alias g-main='git checkout main || git checkout master'

# the other way round: first try `master` then `main`
alias g-master='git checkout master || git checkout main'

# swtich to `test`
alias g-test='git checkout test'

# swtich to `dev`
alias g-dev='git checkout dev'

Docker

In most cases, we use Docker in conjunction with docker-compose for local development.

The most common actions include starting up, shutting down, stopping, and deleting local Docker environments:

# start up environment from `docker-compose.y(a)ml`
# and remove containers for services not defined in this file
alias d-up='docker compose up --remove-orphans'

# shutdown running environment from `docker-compose.y(a)ml`
# and remove containers for services not defined in this file
alias d-down='docker compose down --remove-orphans'

# stop and remove recently started docker environments
# as defined in `docker-compose.y(a)ml`
alias d-rm='docker compose rm -s -f -v'

# stop all running docker containers
alias d-stop='docker kill $(docker ps -q)'

Kubernetes

As last thing, I want to present is a common method to make life easier with kubectl:

alias k='kubectl'

With this you are able to do things like

k delete pod my-awesome-service-0123456789-abcde

In total, a savings of 6 characters per operation can definitely be worth it. 😁

Conclusion

As mentioned: These aliases are only meant as recommendations. There may be changes in certain places that are tailored to one’s own work routine.

You can find an up-to-date version in this gist.

Have fun while trying it out! 🎉