When I was first learning to code, I was working on a bunch of tiny projects and just saving them on my computer. My files were getting disorganized, and it was starting to become hard for me to find my projects and pick up where I left off. I wanted to get more organized and I also wanted to make my code publicly available, so I could showcase both my projects and their source code. That’s when I started learning about git and GitHub!
I first learned how to use git from my patient husband. He showed me how to use the command line, and explained the concept of adding, committing, and pushing code. If you think about version control like shipping a package, it works like this: when you add changes, you’re adding contents to the package; when you commit changes, you’re taping the package shut; when you push changes, you’re shipping the package. So, with every add, commit, and push, you can think of yourself sending a tiny package.
With every small change I made, I practiced committing. I typed
git add .,
git commit -m “tiny change”, and
git push over and over, trying to get the steps stuck in my memory, the keys added to my muscle memory.
Fast forward a few years, and I’ve pushed a lot of commits, over 1,300 in the last year. However, I have moved on from my days of typing those 3 commands over and over and started using aliases.
I first saw an engineer using aliases when I was a student at General Assembly. One of my instructors was walking our class through a demo, and he was navigating his environment and making commits so fast, it was like watching a master chef chopping an onion. For anyone new to programming, watching an experienced engineer work is both exhilarating and daunting at the same time. It’s exciting to see how well they work within their environment and how fast they move, but it can also make you think, “How am I ever going to be that fast?”. At least, that’s how I felt.
Over time, I’ve learned that being the fastest isn’t necessarily what you should be after. Though being fast can be beneficial, being efficient, and not wasting your time on meaningless tasks, is the key to your success as a programmer.
This is where aliases can really come in handy. I primarily use them for a variety of commands in my bash profile. What is a bash profile, you ask? A bash profile is a hidden file where you can add custom settings for your command line interface. Here’s a great blog post that goes into more detail. I’m using bash, hence, bash profile. If you’re using something other than bash, you’ll access your settings elsewhere. Here are the git aliases I’ve set up in my bash profile:
1 2 3 4 5 6 7 8 9 10 11 12 # Aliases alias gs="git status" alias gd="git diff" alias gco="git checkout" alias gcom="git checkout master" alias gst="git stash" alias gb="git branch" alias gcm="git commit -m" alias ga="git add" alias gl="git log" alias gpo="git push origin" alias gpom="git push origin master"
Now, instead of
git add . when I want to stage files for a commit,
git commit -m “tiny change” when I want to commit files, and
git push when I want to push to my branch, I only have to type
gcm “message”, and
gp. When the bash interpreter sees an alias, it simply substitutes the full text for the alias. For example, based on my aliases above, bash substitutes
git add when I type
Now that I’ve added these and other customizations, I view my bash profile as a key part of my development environment. In fact, many developers keep a copy of their bash profile on GitHub, so it’s always in version control and they never lose it when they switch computers.
I’ve made over 1,300 commits in the last year, so I wanted to see if these aliases had saved me any time.
Let’s say that for every commit, I typed those 3 commands I mentioned earlier separately. Even though my commit messages varied in length, let’s keep the commit message length constant for this example. Then, let’s assume that it took me ~200ms for each keystroke.
Here’s some math:
Typing out the following 3 commands yields 44 keystrokes:
git add . → 9 keystrokes git commit -m “tiny change” → 27 keystrokes git push → 8 keystrokes
44 keystrokes * 1300 commits = 57,200 keystrokes
57,200 keystrokes * 200ms / keystroke = 11,440,000ms = 11,400s = 190 minutes
So, if I had typed out those 3 commands for every commit I’ve made in the last year, that would have accounted for about 190 minutes.
But, instead of all of that typing, I used the aliases in my bash profile.
ga . → 4 keystrokes gcm “tiny change” → 17 keystrokes gp → 2 keystrokes
Typing out these 3 commands yields only 23 keystrokes, almost cutting my keystrokes in half!
23 keystrokes * 1300 commits = 29,900 keystrokes
29,900 keystrokes * 200ms / keystroke = 5,980,000ms = 5,980s = ~100 minutes
So, using the aliases, I calculated that I spent about 100 minutes typing out commit commands in the last year.
With a few assumptions and some simple math, you can see that these aliases saved me ~90 minutes over that period of time. Even though that might not seem significant, the idea of shaving off little bits of time with repeated actions is a concept that has a TON of applications in programming, and you may eventually discover a problem to solve where you can save hours rather than minutes.
Now it’s your turn. If you haven’t set up aliases yet, you can use the ones I’ve created, or add your own. It’s your development environment, so customize the setup based on what makes the most sense for you. Think about places in your workflow where you’re doing the same thing over and over. Can you speed it up in any way or write a function to automate the task in order to save yourself some time? Or, if you’ve already done this in any part of your workflow, I’d love to hear about it, so let me know!