Overtime, I’ve collected a lot of git aliases and adopted some recommended git workflow. This post summarizes how I now use git for almost everything.

I track almost all my dot files in a config repo on Github.

Git diff with Matlab package directory

While in grad school, I wrote a lot Matlab codes. Ultimately, I attempted to unify most of the codes and developed an object-oriented MATLAB “toolbox” for quickly implementing and testing numerical methods on a set of example problems using a variety of Finite Difference based spatial discretizations including the ENO and WENO.

At the time, folders containing class definitions in Matlab had a special character prefix, e.g. +Dir01/file.m. A normal git diff had issue with this naming convention, causing errors such as

errr while processing command line Not an editor command +Dir01/file.m

The following git alias, courtesy of stackoverflow helped resolve this issue

[difftool "vimdiff"]
    cmd = vimdiff -- \"$LOCAL\" \"$REMOTE\"

Working with branches

I now use the feature branch workflow: all feature development take place in a dedicated branch and not the master branch. When it comes to integrating the feature branch into master, I up for the rebase approach. There are many who prefers the merge approach over rebase, and vice versa. While working on a moderate-sized project, I prefer rebasing as it preserves a clean project history. I have in my .gitconfig the following alias:

rb = !git branch before-rebase-$(date +"%A-%F-%H_%M")-$(git rev-parse --abbrev-ref HEAD) && git rebase

This creates a temporary branch prefixed with before-rebase with the date and time and the current branch. This way, if I mess up resolving any conflicts, I can reset and restart again.

References