Some notes about my git setup

When I started using git regularly I found most terminal commands hard to understand. As a result, in the beginning I only used git through Sourcetree.

As time progressed, I got more comfortable with its key concepts and started doing more operations through the terminal. Currently I do most git related operations in the terminal. I use Sourcetree mostly for diffs or staging lines/hunks (instead of whole files).

Doing most git things in the terminal plays well with my development workflow which relies on Vim/Tmux.

I use gitsh, an interactive shell for git. This post goes into more details on some of its features. gitsh allows me to have a dedicated tmux pane for git related things. In that pane, I don’t have to prefix any of the commands with git, I can simply press the enter key to check the status, I can use all my aliases, I can use tab completion. The key thing with gitsh is that it is only useful if you have a dedicated pane/window/tab where you do all git stuff.

Whenever I am not using gitsh I am using the command g as a replacement for git. This (only) saves me 2 keystrokes but it is still useful, has low maintenance overhead and does not disrupt my development environment.

I use git aliases for my most common commands. Note that I use git aliases instead of command aliases because with git aliases I can have tab completion features (this is very useful when checking out or rebasing branches with large names for instance).

My most used commands are related with rebasing or rewriting history (my favourite git features):

ri = rebase -i
r = rebase
rim = !git ri master
rc = rebase --continue
ra = rebase --abort
fixup = commit --fixup
pf = push -f origin
plr = pull --rebase

If you are used to rewriting the history then you should set rebase.autosquash to true.

Some aliases are useful for commands I always tend to forget (or for which I find the git API cryptic):

uncommit = reset --soft HEAD^
unstage = reset
last = checkout -
st = stash -u
dlb = branch -D
drb = push origin --delete
sla = log --oneline --decorate --graph --all -20
sl = log --oneline --decorate --graph -20

I usually commit within Vim while using the vim-fugitive plugin. I love how it helps me write good commit messages since it indicates if the title of the commit has surpassed the 50 characters limit, and it formats the body of the commit to comply with the 72 characters limit.

I have a git template message to remind me to write good commit messages.

I have two machines that share my git configuration. Since they both need to have different user information (e.g. work e-mail vs. personal e-mail) I use a different local configuration file in each machine.

Moving forward, the change I hope to make to my overall setup is relying on vim-fugitive for most of the tasks I use Sourcetree. That way I have less reasons to move away from the terminal.

Let me know about aspects of your git/dev setup. Some of what you find in this post I learned from somebody else.