My Git environment

Here are some things I've done to make Git easier to use. There are probably better ways (ex. Git "native" aliases etc.) to do some of these things, but these work for me. This is a work in progress.

Here are some aliases I put in my .bashrc :

alias gb='git branch'
alias gbv='git branch -v'
alias gbva='git branch -va'

alias gci='git citool'

alias gds='git diff --stat'
alias gdsmfh='git diff --stat master FETCH_HEAD'
alias gdtmfh='git difftool master FETCH_HEAD'

alias gl='git log --pretty=short'
alias glf='git log --pretty=fuller'
alias gls='git log --stat'

alias gs='git status'
alias gsh='git show'

There's also a very useful "Git completion" script available here :
* http://repo.or.cz/w/git.git?a=blob_plain;f=contrib/completion/git-comple...

By using it you get completion (via tab) of Git branches and common command options. Most useful, however, is the ability to always see the branch you're on, and the state of the branch.

Here's how this is setup in my .bashrc :

# Source the Git completion script
source ~/.git-completion.sh
#
# with .git-completion.sh, can show dirty, unstaged (*) and staged (+) after git branch
GIT_PS1_SHOWDIRTYSTATE=true
#
# Reduce PWD in prompt to last 20 chars of PWD
PROMPT_COMMAND='if [ ${#PWD} -gt 20 ]; then myPWD="..${PWD:${#PWD}-20}"; else myPWD=$PWD; fi'
#
# __git_ps1 defined in .git-completion.sh
# append branch name to PS1 if in git repo
PS1='\h:$myPWD$(__git_ps1 " (%s)") \$ '

Sample output showing name and state of master branch :

myhost:/tmp/gitTest (master*+) $ git status
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Changes to be committed:
# (use "git reset HEAD ..." to unstage)
#
# new file: test.txt
#
# Changed but not updated:
# (use "git add ..." to update what will be committed)
# (use "git checkout -- ..." to discard changes in working directory)
#
# modified: master-file

Categories: