How I Git

Being part of an agile team requires coding and eventually reviewing code from others.

Code organization Link to heading

In order to make it easier to switch between my code and some code to be reviewed, I maintain multiple clones of the repository.

These clones will be located under a short name representative of the project and then have names like either main or review.

.
├── been-there
   ├── main
   └── review
├── mock-location
   ├── main
   └── review
└── espresso-tips
    ├── main
    └── review

Shell enhancements Link to heading

A few aliases on my .zshrc allow to quickly jump between those different locations. The pattern I usually apply for the alias consists of 4 letters, where the third is meaningful to indicate the project, and the fourth indicates either main or review.

cdbm=cd ~/Code/been-there/main

cdbr=cd ~/Code/been-there/review

Git aliases Link to heading

To make it easier to fetch, pull, checkout, and all other commands we normally use in Git, I rely on some plugins for Oh My Zsh.

My list of plugins include:

  • git
  • git-extras
  • git-flow
  • git-flow-avh
  • git-prompt
  • git-remote-branch
  • github
  • gitignore

These plugins add some aliases to my shell and I can easily perform change between branches, cleanup my repo, and approve those PRs.

These are a few of the ones I use the most:

glola = 'git log --graph --pretty='\''%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'\'' --all'

gco = git checkout

gfa = git fetch --all --prune

gup = git pull --rebase

gb = git branch

gc = git commit -v

To cleanup repos that I eventually checked-out:

gco -- . && gco master && gb -l | grep -v ^\* | xargs git branch -D