Awesome Git Shortcuts

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…


This content originally appeared on DEV Community and was authored by Sunny Golovine

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


This content originally appeared on DEV Community and was authored by Sunny Golovine


Print Share Comment Cite Upload Translate Updates
APA

Sunny Golovine | Sciencx (2021-04-23T16:00:33+00:00) Awesome Git Shortcuts. Retrieved from https://www.scien.cx/2021/04/23/awesome-git-shortcuts/

MLA
" » Awesome Git Shortcuts." Sunny Golovine | Sciencx - Friday April 23, 2021, https://www.scien.cx/2021/04/23/awesome-git-shortcuts/
HARVARD
Sunny Golovine | Sciencx Friday April 23, 2021 » Awesome Git Shortcuts., viewed ,<https://www.scien.cx/2021/04/23/awesome-git-shortcuts/>
VANCOUVER
Sunny Golovine | Sciencx - » Awesome Git Shortcuts. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/04/23/awesome-git-shortcuts/
CHICAGO
" » Awesome Git Shortcuts." Sunny Golovine | Sciencx - Accessed . https://www.scien.cx/2021/04/23/awesome-git-shortcuts/
IEEE
" » Awesome Git Shortcuts." Sunny Golovine | Sciencx [Online]. Available: https://www.scien.cx/2021/04/23/awesome-git-shortcuts/. [Accessed: ]
rf:citation
» Awesome Git Shortcuts | Sunny Golovine | Sciencx | https://www.scien.cx/2021/04/23/awesome-git-shortcuts/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.