Blaze through commits with git aliases
October 19, 2018 - 2 min read
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 add ., and
git commit --message.
Streamline your workflow to be faster and more productive.
git add .becomes
git commit -mbecomes
git checkout -bbecomes
git commit --amend --no-editbecomes
git log --oneline --decoratebecomes
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
ls -aand you should see a file called
.bash_profileif you don't have
- Open the file with
- 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