My Absolute Must to Have Git Shortcuts

Almost every developer who once started to use Git as a version control system knows how efficient you can be in the console with this tool. With very short commands one is able to check-in and check-out code faster than you think.

All needed steps to interact with your code repository can be executed on command line. There is no need to use any klikibunti​1​ (means some kind of graphical user interface) GUI. But with a right .gitconfig  file in our home directory (~) you can even become faster, much faster! But first things first

.gitconfig File

The .gitconfig file allows the user to make some personal settings which affect git and the way how you can work with the version control system (VCS). Since, I am using git for several years in different project I started to define my own aliases for the standard git commands. Aliases allow you to find a more handy substitution for the standard git commands. So instead of writing git commit -a -m "some nice commit message" you could define e.g. git cam "some nice commit message.

Better Logs

These aliases allow me to find things faster in the log. The commands shows the revision graph. Quite equivalent to that what the GUIs  gives you.

lg1 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)'
lg1a = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all
lgs = log --graph --stat --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)'

lg2 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' 
lg2a = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all
lg = !"git lg1"
ls = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cgreen\\ [%cn]" --decorate
ll = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cgreen\\ [%cn]" --decorate --numstat

Faster Integration

The must to have commands. All standard just add in your [alias] and test these commands:

a = add
cm  = commit -m 
cam = commit -a -m
cia = commit --amend
d = diff
ds = diff --stat
dsh = diff --stat master..HEAD
dc = diff --cached
dt = difftool
mt = mergetool
s = status -s
co = checkout
cob = checkout -b
chp = cherry-pic
ph = push
pl = pull
t = tag
pht = push --tag

Pocket Knife

My personal (Swiss) pocket knife. If you do not know where you find a file, e.g. class, package, config, whatever, you can use these commands to find it.

# Find a file path in codebase:
fg = "!git ls-files | grep -i"

Usage

adam@adam-laptop:~/Development/vim-settings$ git fg visu
.vim/bundle/visual-split

If you are more interested in the content you can use another command. This will grep all files and there lines where your search terms can be located:

# Search/grep your entire codebase for a string:
 gr = grep -Ii

Let’s search for the string “abort”

adam@adam-laptop:~/Development/vim-settings$ git gr abort 
.vim/autoload/pathogen.vim:function! pathogen#infect(...) abort
.vim/autoload/pathogen.vim:function! pathogen#split(path) abort
.vim/autoload/pathogen.vim:function! pathogen#join(...) abort
.vim/autoload/pathogen.vim:function! pathogen#legacyjoin(...) abort
.vim/autoload/pathogen.vim:function! pathogen#cycle_filetype() abort
.vim/autoload/pathogen.vim:function! pathogen#is_disabled(path) abort
.vim/autoload/pathogen.vim:function! pathogen#surround(path) abort
.vim/autoload/pathogen.vim:function! pathogen#interpose(name) abort
.vim/autoload/pathogen.vim:function! pathogen#helptags() abort
.vim/autoload/pathogen.vim:function! pathogen#execute(...) abort
.vim/autoload/pathogen.vim:function! pathogen#is_absolute(path) abort
.vim/autoload/pathogen.vim:function! pathogen#expand(pattern, ...) abort
.vim/autoload/pathogen.vim:function! pathogen#slash() abort
.vim/autoload/pathogen.vim:function! pathogen#separator() abort
.vim/autoload/pathogen.vim:function! pathogen#glob(pattern) abort
.vim/autoload/pathogen.vim:function! pathogen#glob_directories(pattern) abort
.vim/autoload/pathogen.vim:function! pathogen#uniq(list) abort
.vim/autoload/pathogen.vim:function! pathogen#fnameescape(string) abort
.vim/autoload/pathogen.vim:function! pathogen#runtime_findfile(file,count) abort

Your Reminder

Have you forgotten an alias? No problem! Just list your settings with:

# List all aliases 
la = "!git config -l | grep alias | cut -c 7-"

Bibliography

  1. 1.
    Wikipedia . Wikipedia. Klickibunti. https://de.wikipedia.org/wiki/Klickibunti. Published February 2018. Accessed February 2018.