Terminal Aliases for Git: Two Simple Steps
Mindy Wagner, Former Design Director
I like to think I'm a pretty ambitious person, but there's something I find myself abhorringly lazy about. It's the stupidest kind of lazy because it actually makes my job harder and less enjoyable. It's counterproductive to productivity. So what is it? I'm horrible about learning shortcuts. I use very few keyboard shortcuts, even for applications I work in constantly. I am glued to my mouse and don't have custom preferences set up for most programs. When the Viget developers watch me navigate through menus and folders, they must be dying inside.
I've been working on improving in the shortcut area, though. One easy fix came to my attention recently while working with Git, Viget South's favorite version control system. It's a change so easy and helpful, I was embarrassed by how long I had avoided doing it. Thought I'd share so you can stop being lazy too.
If you work with Git on a Mac, you probably run some or all of your commands through Terminal. And in Terminal, you probably find yourself typing out some long and tedious commands over and over again in full. If you watch developers tooling around in there you'll notice they have a set of shorthand commands they use. Git Status becomes "gst", Git Checkout becomes "gco", etc. It seemed pretty magical to me, which I took to mean complicated and too technical to bother with. Turns out those little shorthand commands are called aliases, and it takes about 30 seconds to add a few to Terminal. The payoff is lots and lots of saved keystrokes.
Step 1: Open .profile from Terminal
I do this by typing the following command in Terminal: open /users/username/.profile (where username is the name of the user profile you want to edit)
The open command uses the same default application to open a file as Finder. If for some reason it's not opening in the program you want it to, you can force it to open in TextEdit by changing the command to "open -a TextEdit /users/username/.profile
This should open your hidden .profile file in TextEdit where you can easily make changes. Just don't go crazy within this file. Leave existing items untouched, lest you screw up another application's preferences. Hidden files are hidden for a reason, so proceed with caution.
Step 2: Add your aliases
All you have to do is type "alias [shortcut]='[original command]'
Here's a list of general ones I have set up for Git. You could copy and paste these directly or make your own.
alias gst='git status'
alias gc='git commit'
alias gco='git checkout'
alias gl='git pull'
alias gpom="git pull origin master"
alias gp='git push'
alias gd='git diff | mate'
alias gb='git branch'
alias gba='git branch -a'
alias del='git branch -d'
You can create aliases for anything you type frequently into Terminal, not just Git commands. I also added a few shortcuts to the directories i use most often. Example: alias mamp="cd /applications/mamp/htdocs/"
Save the changes, then fire up Terminal to test out your new cool alias commands. That was painless, wasn't it? Share your suggestions for quick life-energy savers like this one in the comments below!
(Not using Git, but curious about it? Check out this post from the Inspire archives - Git: A Designer's Perspective. You'll also find lots of Git goodness on the Viget:Extend blog, including A Gaggle of Git Tips. Thanks to Chris, who showed me this trick last week, and to David who showed me the same thing about a year ago when I was too lazy to bother putting it into action.)