The most valuable time as a software developer is usually time spent collaborating and thinking. To get as much of that time as possible, reduce the time you spend typing things with your mortal fingers!
Git is a ubiquitous version control system, and becomes more important as many developers begin collaborating on the same code base. If your organization uses Agile development practices, you'll also be creating many branches and updating
master a lot.
- Check out the
- Update your local
masterbranch with the latest changes from the remote
- Create a new branch for your changes
- Commit your changes with a good commit message
- Push your branch to the remote
Without any aliases, this workflow looks like this on the command line:
$ git checkout master $ git pull origin master $ git checkout -b my-feature # Make changes... $ git add . $ git commit -am 'Add my feature' $ git push origin my-feature
This is fine, but sometimes I forget that pesky
-b flag when creating a branch and also get annoyed that I need to state which branch I'm pushing when it's almost always the current one.
With the Git plugin aliases, this workflow takes a lot less work:
$ gcm $ gl origin master $ gcb my-feature # Make changes... $ ga . $ gcam 'Add my feature' $ ggpush # this takes advantage of oh-my-zsh's git_current_branch
Sometimes you need to stash your changes while looking at another branch or doing more complex things in Git:
$ git stash # Do some stuff and come back $ git stash pop
But these aliases come in handy:
$ gsta # Do some stuff and come back $ gstp
There are a lot of handy aliases, including plenty with the various flags you might use for a particular Git subcommand:
$ gd # git diff $ gdca # git diff --cached $ gds # git diff --staged
I love using these, and the shorthand for them is generally intuitable kind of like Vim. I've added a few of my own for command+flag combinations I use commonly, like:
$ goop # "git oops": git reset --soft HEAD~1 $ gun # "git unstage": git reset HEAD --
I also checkout and update master then prune cleaned up remote branches so often that I made a single command,
upr (for "update repo"), that does this all for me.
I work in Python and Django most days. The ease and length of my aliases in this arena reflect that; the more frequently I run a command, the shorter its alias:
$ python manage.py runserver # Nope $ ./manage.py runserver # Nope $ run # There we go
$ pipenv shell # Nope $ psh # Yep
$ pip install -r requirements.txt # Hmmm $ prq # Indeed!
There are a few general command utilities that I use often enough to slim them down too. The one I use the absolute most is
named, which expands to
find . -name. Then I just ask for files
named "*.py"! I also default
grep to using colors and line numbers by aliasing it to
grep -n --color=auto. I can use the bare
grep by typing
\grep on the rare occasions where it's needed.
You can see all of my aliases here.
The point of all this is that you should spend time thinking about what you want to do and as little time as possible doing what you want to do when using the command line or writing code. I'm able to reincorporate all the time I save into more thinking—usually about all the bugs I've introduced 😉