Git Faster (My Git Aliases)
The Problem:
Half tutorial, half work flow post.
I commit a lot, which is a best practice. If I make mistakes which aren't easily fixable, I can easily revert to a previous commit.
When Laurie Voss from npm spoke at Hack Reactor, he mentioned that there is a great amount of efficiency to be gained from optimizing frequent tasks.
The Math:
Let's estimate that each commit takes me 30 seconds from git status
to saving the commit message.
If I commit 20 times per day, that's about 10 minutes gone. So for each week, that's 50 minutes I could be making tea writing more code. Just to hammer the point home, that's around 42 hours per work year.
The Solution
To make things quicker and reduce strain on my hands, I've added some aliases which allow me to make git commands more quickly.
There are many ways to accomplish this, all on Stack Overflow and the like, but here's how I do it.
- First, I set an alias I took from here to quickly access hidden Mac files. I type showFiles in the terminal to show any hidden files I want to access. When I'm done, I type hideFiles and they're all gone. My Finder looks like this when I'm showing the hidden stuff:
- Open your .bash_profile file using your favorite text editor. My file is in my user folder near the top (see the picture above). Oh hey! Look what's there...the show and hide file aliases you've already created!
- Add your alias. My favorite is shown below. First add to the global .gitconfig file in the terminal: Then add the alias to the bash profile. Follow the example syntax dutifully! Whitespace and single quotes matter here. Save the file and restart the terminal. Now you can just type gs in the command line instead of git status. Magic.
Oh you fancy, huh?
This alias will git push origin {whatever branch you're currently on}
. (no need for editing the .gitconfig
file)
On master branch? Type po
and you have git push origin master
.
On feat/SuperAwesomeFeature branch?
Type po
and you have git push origin feat/SuperAwesomeFeature
.
Super quick and awesome for all of those branches you've been cutting.
comments powered by Disqus