Blaze through commits with git aliases
October 19, 2018 - 2 min
When you're forced to stop and make a commit after reaching a milestone, sometimes using Git can feel like a crutch rather than a tool. If you sharpen your commit tool to the point where committing is a breeze, you can have more organized code with less chance of losing work.
Save More than a Few Keystrokes
Here's an example of a quick commit with aliases for git status, git add ., and git commit --message.
Streamline your workflow to be faster and more productive.
Explanation:
git statusbecomesgsgit add .becomesgaagit commit -mbecomesgcm
Other examples:
git checkout -bbecomesgcobgit commit --amend --no-editbecomesgcanegit log --oneline --decoratebecomesgll
You can also make shortcuts for any Git command or any other terminal command.
How to Add Aliases
Simply add the following to your .bashrc file.
- Navigate to your home directory
cd ~. - Enter
ls -aand you should see a file called.bashrc. (or.bash_profileif you don't have.bashrc) - Open the file with
open .bashrcornano .bashrc. - Paste in the following, making changes as needed.
#Aliases - general
alias c='clear'
# Alias - git
alias ga='git add'
alias gaa='git add .'
alias gb='git branch'
alias gc='git commit'
alias gcm='git commit --message'
alias gl='git log'
alias glo='git log --oneline --decorate'
alias gld='git log --pretty=format:"%h %ad %s" --date=short --all'
alias gs='git status'
alias gco='git checkout'
alias gcob='git checkout -b'
alias gd='git diff'
alias gds='git diff --staged'
alias gcane='git commit --amend --no-edit'All new windows will have these aliases enabled. You can also run . ~/.bashrc in an existing window/tab to enable them.
Bonus - Add Colors and Features
If you like to add more features and colors to terminal, check out Bash-Git-Prompt which can be installed with Homebrew.
Example of Bash-Git-Prompt features