Dave's Blog

Productivity: bash aliases


August 21, 2018

A lot of my colleagues use various visual git clients. When I migrated our source code from Vault to git in 2017 my CTO advised me strongly to use bash instead of visual tools.

I took his advice and now I advise all new starters to do so.

While I think diffs are hard to read in bash (I know you can set a diff tool but there is one in VS) and it is easier to right-click files > Stage in the VS Team Explorer than add files in bash.

However I prefer to use bash for pretty much everything else git-related. The use of bash, and getting used to the shortcuts (that's a fairly large jump for most people coming from a Windows background) means that I've become happy with it such that I want to explore what more I can do to speed up desktop activity.

I have specified some shortcuts of my own into bash by adding them to my .bashrc file and asking bash to use it. (See how to get started with a .bashrc.)

Here is part of my .bashrc file. This is stored in my Windows Users root folder (eg, C:\Users\dave.bashrc)

alias gmm='git checkout master;git pull; git checkout -; git merge master'

I use this all the time. I've committed my code and tests. I've pushed to my branch so my work is secure. Now I want to pull in the latest from master. Typing gmm is much easier than (in VS) moving to a new branch; letting VS reload the project; pulling down; letting VS reload the project; then moving back to my branch and so on.

alias gc='git checkout '

You can chain these aliases together. Let's say I want to throw away what's in my branch and update with the latest master. I just do this:

gc .;gmm

Because my aliases don't end in semi-colons they accept parameters. In this case the dot says "undo all the changed files", so the whole command thorws away the changes and then refreshes the branch with the latest code on the master branch on the remote repo.

alias gl2='git log -2 '

lets me see the last two changes That's often all I want to see. Those are changes by anyone. What if I want to see just mine?

alias glmine='git log --author=dave'

lets me see my changes.

glmine -2

lets me see my last two changes.

alias gst='git status '

saves 7 key strokes per check. Do the maths!.

Further from git

alias aproj='cd U:; cd Users/dave/Documents/a_proj'

switches my working folder to my projects folder.

Getting started with a .bashrc

To get started get my bashrc file and save to your root folder as .bashrc. Then run (in bash, replacing dave with your username) to load the aliases into bash:

source C:/Users/dave/.bashrc