Useful Git and Docker Aliases for ZSH

Firstly, this article assumes a couple of things:

  • You already have ZSH and possible oh-my-zsh installed.
  • You already have both Git and Docker installed.
  • You have the correct permissions to install packages locally.

To get started, open up your .zshrc config and jump to the # Example aliases block:

sudo nano ~/.zshrc

Git Aliases:

alias gs="git status"
alias ga="git add -A"
alias gc="git commit -m "
alias gp="git pull"
alias gpu="git pull upstream"
alias gpo="git pull origin"
alias gpum="git pull upstream main"
alias gpom="git pull origin main"
alias gpud="git pull upstream develop"
alias gpod="git pull origin develop"
alias glog='git log --pretty="%C(Yellow)%h %C(reset)%ad (%C(Green)%cr%C(reset))%x09 %C(Cyan)%an: %C(reset)%s" -7 --date=short'

The following useful alias requires the https://github.com/Nutlope/aicommits package to be installed and configured with the OpenAI platform (ensure you add billing details and regenerate a new token for it to work).

Additionally there’s a useful alias that will automatically generate a commit using AI and push your work up using the current branch name to save even more time.

aicommits

alias gcm="aicommits"
alias gcmp="echo Y | aicommits && git push --set-upstream origin $(git_current_branch)"

Docker Aliases:

The following commands require the https://github.com/devemio/docker-color-output package installed in your shell to create beautiful, colorized outputs for docker.

docker-color-output

alias dc="docker-compose"
alias dcps="docker-compose ps | docker-color-output"
alias dps='docker ps --format "table {{.ID}}\t{{.Names}}\t{{.Networks}}\t{{.State}}\t{{.CreatedAt}}" | docker-color-output'

Other Useful Aliases:

#1 Automatically format .php files with the PHP Code Beautifier in the PSR-12 standard. Requires the https://phpqa.io/projects/phpcbf.html package installed locally.

alias fix="php $HOME/.config/composer/vendor/bin/phpcbf --standard=PSR12 -v -p"

#2 Display actually useful and beautiful directories in your terminal. Requires the Exa package installed locally.

Exa

alias ls="exa --long --header --group-directories-first --icons -la --classify --all --time-style=long-iso --color-scale -g"


Finally, don’t forget to restart your shell for the above changes to take effect.

Leave a comment