Besides VSCode, git is probably the most used tool in my toolbox. Over the years I've learned that there are a few common git commands that I always repeat, so I created some sensible aliases to help me move faster. I wanted to share these aliases with any folks here that might find them helpful.
Git Status
By far the most frequently used alias is my alias to git status
. I aliased git status
to gst
.
Git Add
The normal command for staging files for a commit is git add -A
or git add .
or git add some/file/name.ts
. I created an alias for it simply to ga
Git Commit
Simmilarly to git add, I also created an alias for git commit. The typical command is git commit
or git commit -m <COMMIT_MSG>
, I aliased git commit
to gc
and git commit -m
to gcm
. Now you can type out a commit message like gcm "some cool messsage"
Git Diff
For git diff I added two aliases. First is gd
which is an alias to git diff
. However I also have gdc
which is aliased to git diff --cached
, for viewing diffs after you have staged your files.
Git Push
I also aliased git push
to gp
. Not much more to say here.
Git Checkout
For quickly checking out branches I aliased git checkout
to gco
. For new branches I also created a gcob
alias that does git checkout -b
.
Git Branch
For quickly listing branches I aliased git branch
to gb
.
Benefits
Besides being much faster to type out, another benefit of these aliases is that you can still use flags like normally. Say you want to push a new branch to a remote. Without aliases it would look like this: git push -u origin my_branch
. But with aliases I can simply type gp -u origin my_branch
, not a significant savings but when you type the command out thousands of times, it starts to make a difference.
Try them out yourself
While there are many ways you can create a git alias, I did it in the most simple way by just adding an alias to my .bashrc
. Here are all the aliases I mentioned in this post
alias gst='git status'
alias ga='git add -A'
alias gc='git commit'
alias gcm='git commit -m'
alias gd='git diff'
alias gdc='git diff --cached'
alias gp='git push'
alias gco='git checkout'
alias gcob='git checkout -b'
alias gb='git branch'
If you want to give these a test drive, paste this code block directly into your terminal and it will enable these aliases for the current session. If you like them you can then add it to your .bashrc
/ .zshrc
/ etc.
If you liked this post check out some of my other writing here
Top comments (0)