Faster Git Workflow
How many times during a normal day you write git checkout or git commit –amend. Probably many, many times. Probably more than you want to admit without asking yourself what in the name of god made you choose this life path.
Nevertheless, I will try to improve that. Or at least I will try to make it hurt a little less.
Use g instead of git #
This will save you two keystrokes per command, or even more. This is the simplest trick. Simply define an alias in your bashrc(or zshrc file if you have a hipster side) and assign git to the command g
But why stop there? We can define g smarter. Instead of defining it as an alias we can define it as a function, and make it act like
git status if invoked without parameters.
#!/bin/bash if [ "$#" -eq 0 ]; then git status else git "$*" fi
Put the above script in a
~/bin/g file, and append the following to your shells rc file
~/.gitconfig file you can shorten command even more. Here is a snippet to give you an idea.
[alias] a = add st = status ci = commit ca = commit --amend br = branch co = checkout df = diff dfc = diff --cached lg = log -p who = shortlog -s -- pl = pull ps = push pru = remote prune origin
After this you can simply type
g co master to check out your master branch.
Show branch and status indicator in your PS1 #
The above indicators and branch name in the status can be easily achieved with oh-my-zsh or similar. Use it!
Create custom git scripts #
To really improve your workflow you should create programs that can make git even smarter. For example you can encapsulate a complex git command in a nicely named script.
For inspiration look at holman/dotfiles.