Trent Yang

Git ABC - Start remembering and stop googling

2019-05-27 cover photo

I was once a Git googler (I mean I google Git a lot :P) until one day I sit down and decide to spend a bit of time remembering the most common commands. My approach was to develop an easy-to-understand framework and use systematic aliases to replace Git commands. If that sounds interesting, I present you the Git ABC. git abc

Git ABC

There are three stages a file change (for example adding a new line) need to go through in Git. I use A, B and C to represent them.

Stage A

Unstaged changes and untracked files are in stage A. git status will show them in red. Stage A

Stage B

Once we git add -A, changes will be moved to stage B. git status will show them in green. In Git lingo, these changes are now ‘staged’. Stage B

Stage C

After we git commit -m, changes will be moved to stage C (committed stage).

Alias

Now comes the fun part. Git ABC

Move forward

Git users should already be familiar with git add and git commit so I choose the following aliases to move changes forward

Move backward

I use go to undo changes. We can think of it as ‘go away’ :)

Check differences between stages

I use gd (Git Diff) to check the difference.

Here I listed all the aliases bellow so that you can copy and paste into your shell config files.

# move forward
alias ga='git add -A'
alias gc='git commit -m'

# move backward / undo
alias go='git checkout'
alias gou='git clean -id' # u means Untracked files
alias gob='git reset HEAD'
alias goc='git reset --soft HEAD~1'
alias gocc='git reset --hard HEAD~1' # c means Confirm

# check difference
alias gd='git diff'
alias gdbc='git diff --cached'
alias gdac='git diff HEAD'
alias gdc='git diff HEAD^ HEAD'

Bonus aliases

Some of my fun aliases do not fit into the framework above so I lump them here :)

# status
alias gs='git status'

# log
alias gl='git log'
alias glo='git log --oneline --decorate'

# stash and apply
alias gst='git stash'
alias gap='git stash apply --index'

# rebase
alias gr='git rebase'
alias grm='git fetch origin master:master && git rebase master'
alias grs='git rebase --skip'
alias grc='git rebase --continue'
alias gri='git rebase -i master'

Go above and beyond

At last, I encourage you to go crazy and create your own aliases for profit and fun :)

go crazy