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.
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.
Unstaged changes and untracked files are in stage A.
git status will show them in red.
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’.
git commit -m, changes will be moved to stage C (committed stage).
Now comes the fun part.
Git users should already be familiar with
git add and
git commit so I choose the following aliases to move changes forward
alias ga='git add -A'(Git Add) move changes from stage A to B
alias gc='git commit -m'(Git Commit) move changes from stage B to C
go to undo changes. We can think of it as ‘go away’ :)
alias go='git checkout'undo changes from A
alias gou='git clean -id'(GO Untracked) remove un-tracked files from A
alias gob='git reset HEAD'(GO from B) move changes from B to A
alias goc='git reset --soft HEAD~1'(GO from C) move changes from C to B
alias gocc='git reset --hard HEAD~1'(GO from C Confirm) remove the whole commit from C
Check differences between stages
gd (Git Diff) to check the difference.
alias gd='git diff'Difference between A and B
alias gdbc='git diff --cached'Difference between B and C
alias gdac='git diff HEAD'Difference between A and C
alias gdc='git diff HEAD^ HEAD'All changes from the last Commit
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'
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 :)