Git: Aliases

git-6-728

With aliases, you can avoid typing the same commands over and over again. Aliases were added in Git version 1.4.0. I found in githowto.com/aliases a great set of aliases that I really use everyday and I would like to share.

One of the most useful alias is “git hist“, it shows you all the last commit, showing the branch tree and the commit message, all in a short form (remember to hit ‘q’ to exit the hist command).

git-hist

In windows you just need to add the following section to the .gitconfig file under %HOMEDRIVE%%HOMEPATH% folder (usually is something like ‘C:\Users\michael\.gitconfig’).

[alias]
  co = checkout
  ci = commit
  st = status
  br = branch
  hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
  type = cat-file -t
  dump = cat-file -p

or you can run these commands in the command-line prompt:

git config --global alias.co checkout
git config --global alias.ci commit
git config --global alias.st status
git config --global alias.br branch
git config --global alias.hist 'log --pretty=format:"%h %ad | %s%d [%an]" --graph --date=short'
git config --global alias.type 'cat-file -t'
git config --global alias.dump 'cat-file -p'

If you don’t already have a .gitconfig file, this could be a default settings file you can use:

[merge]
	tool = kdiff3
[mergetool "kdiff3"]
	path = C:/Program Files/KDiff3/kdiff3.exe
[diff]
	guitool = kdiff3
[difftool "kdiff3"]
	path = C:/Program Files/KDiff3/kdiff3.exe
[user]
	name = Your Name
	email = youremail@me.com
[alias]
  co = checkout
  ci = commit
  st = status
  br = branch
  hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
  type = cat-file -t
  dump = cat-file -p