Git Usage

Git config aliases and git workflows

2014-09-05 — Rylan Santinon

Git Aliases

To be more productive with git, it's often useful to be able to set aliases for commands that are executed often.

Show status concisely:
$ git config --global alias.st 'status -s'
$ git st
Show a concise and colorful log:
$ git config --global alias.lg 'log --graph --color --decorate --pretty=oneline --abbrev-commit --all'
$ git lg
Diff last commit:
$ git config --global alias.dl 'diff --color HEAD~1'
$ git dl
Show number of insertions and deletions of modified files:
$ git config --global alias.ds 'diff --numstat'
$ git ds

More shortcuts

ad = add
co = checkout
ca = commit -a --verbose
bra = branch -a
today = log --since=midnight --author='username' --oneline
ls = ls-files

Git workflows

There are a bunch of ways git can be used when doing feature development on a team but the workflow that I've become accustomed to is the rebase workflow which would look something like this:

$ git checkout master
$ git pull --rebase
$ git checkout -b new-feature
After creating the branch, do some work and commit:
$ git commit -m "First commit"
Make some more changes and commit again:
$ git commit -m "Last commit"
Interactive rebase (squash) and push:
$ git rebase -i HEAD~2
$ git push

When doing this rebase, pick the first commit and then squash the other ones. Git will then open up a text editor for you to edit the commit messages.