Speed up your Git commands with aliases

4th September 2022 | 2 min read
gitaliasescommand lineterminalbashrczshrc
showing github commits

What's an alias.

You can think of an alias as a shortcut for a command. For example, if you want to run the command git status you can create an alias for it. This means that you can run the command gs instead of git status. This is useful because it saves you time and makes your commands easier to remember.

You can do lots of things with aliases, but we're going to focus on git commands.

This will save you time and make your commands easier to remember.

How to create an alias

The fastest way to create an alias is to edit your .bashrc or .zshrc file. This is a file that runs every time you open a new terminal window. You can find it in your home directory.

Note: if you don't have one of these files, you can create one. Just make sure you name it .bashrc or .zshrc and that it starts with a .. Make sure you create them in your home directory.

If you're using VS Code, you can open it by typing code ~/.bashrc or code ~/.zshrc into your terminal.

If you're using another editor, you can open it by typing open ~/.bashrc or open ~/.zshrc into your terminal.

Or you can use VIM by typing vim ~/.bashrc or vim ~/.zshrc into your terminal.

~/ is a shortcut for your home directory.

Now Let's setup our aliases.

This can be done by typing:

alias gs='git status'

Save your file with the changed mentioned above and reload the terminal. You can do this by typing source ~/.bashrc or source ~/.zshrc into your terminal.

This will create an alias for git status called gs. You can do this for any git command.

Aliases for git commands

My aliases for git commands that I use daily are:

alias gs="git status"
alias gc="git checkout"
alias gcm="git commit -m"
alias gpo="git push origin"
alias gplo="git pull origin"
alias gnb="git checkout -b"
alias ga="git add"
alias gplups="git pull upstream"
alias graups="git remote add upstream"

Hope this will help you speed up your git commands.

Bonus

You can also create aliases for other commands. For example, I have an alias for nuking node modules and lock files.

alias nuke-npm="rm -rf node_modules/ package-lock.json"
alias nuke-yarn="rm -rf node_modules/ yarn.lock"
Read More Posts