My git set up

  |   Source

Content of my .gitconfig,

[apply]
    whitespace = nowarn
[user]
    name = my name
    email =my@email.com
[core]
    ; @see http://comments.gmane.org/gmane.comp.version-control.git/166098
    filemode = true
    ;autocrlf = false
    ignorecase = false
    ;autocrlf=false
    ;safecrlf=true
[color]
    diff = auto
    status = auto
    branch = auto
    ui = auto
[alias]
    ca=commit --amend
    cl = clean -fxd
    au = add -u
    st = status -sb #short status output for geeks
    stu= status --untracked-files=no
    r = rebase
    c = commit
    co = checkout
    b = branch
    s=show
    l = log --pretty=format:'%C(yellow)%h%Creset %ad %s %Cred(%an)%Creset' --date=short --decorate --graph
    d =diff
    da= diff --name-only # get the file list
    ds = diff --stat
    dw=diff --word-diff #highlight word changes
    dc = diff --cached
    dcs = diff --cached --stat
    t=stash
    a=add
    f=format-patch -n --stdout
    rh=reset --hard
    rs=reset --soft
    undo=reset --soft HEAD^
    rs=reset
    cnt=count-objects
    ps=push
    p=pull --rebase
    w = whatchanged
    sb = show-branch
    cp = cherry-pick
    # @see http://magazine.redhat.com/2008/05/02/shipping-quality-code-with-git/
    cpnx = cherry-pick --no-commit -x
    rl = reflog
    lp = log -p
    lt = log --topo-order
    gl = log --graph
    m = merge
    mt= mergetool
    me = merge --no-commit --no-ff
    brm = branch --merged
    brnm = branch --no-merged
    rnc = revert --no-commit
    com = checkout master
    glt = log --pretty=format:'%h : %s' --topo-order --graph
    phm = push heroku master
    pom = push origin master
    puom= pull origin master
    untrac=rm -r --cached
    #produce patch for hg
    hgp = show --format="From: %an <%ae>%n%s%n%b" -U8
    show-root-folder = rev-parse --show-toplevel
    forward = pull --ff -r
    u = !git stash && git pull --rebase && git stash pop
[sendemail]
    smtpencryption = tls
    smtpserver = smtp.gmail.com
    smtpuser = myname@gmail.com
    smtpserverport = 587
[github]
    user = github user
[push]
    default = tracking

[merge]
    branchdesc = true
    log = true
    tool = vimdiff
[diff]
    tool = vimdiff
[mergetool]
    prompt = false

Content of my .bashrc,

# enable bash completion in interactive shells
# @see http://www.simplicidade.org/notes/archives/2008/02/bash_completion.html
if [ -f /etc/bash_completion ]; then
    # ArchLinux
    . /etc/bash_completion
elif [ -f /etc/profile.d/bash-completion.sh ]; then
    # Gentoo Linux
    . /etc/profile.d/bash-completion.sh
fi
. $HOME/bash_completion.d/gibo-completion.bash
. $HOME/bash_completion.d/git-completion.bash

function parse_git_branch ()
{
   git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
}

function simpleprompt()
{
   if test -n "`type -t git`"; then
      PS1="\$(parse_git_branch) \\$ "
   else
      PS1="\\$ "
   fi
}

alias gcd='cd $(git rev-parse --show-cdup)'
alias g="git status --short -b"
alias gn="git status --untracked-files=no --short -b"
alias gfl="git diff-tree --no-commit-id --name-only -r"
alias ga="git add"
alias gaa="git add ."
alias gau="git add -u"
alias gc="git commit -m"
alias gca="git commit --amend"
alias gb="git branch"
alias gbd="git branch -d"
alias gco="git checkout"
alias gcob="git checkout -b"
alias gt="git stash"
alias gta="git stash apply"
alias gm="git merge"
alias gmt="git mergetool"
alias gr="git rebase"
alias gl="git log --oneline --decorate --graph"
alias gs="git show"
alias gss="git show --stat"
alias gd="git diff"
alias gds="git diff --stat"
alias gdc="git diff --cached"
alias gdcs="git diff --cached --stat"
alias gbl="git blame"
alias gps="git push"
alias gpl="git pull"
alias cdgr='cd $(git rev-parse --show-toplevel)' #goto root dir
function gu(){
    local st=`git status --porcelain --untracked=no`
    if [ -z "$st" ]; then
        git pull --rebase
    else
        git stash && git pull --rebase && git stash pop
    fi
}

function gsrp(){
  if [ -z "$1" ]; then
      echo "Usage: gsrp old_string new_string (string could be perl regex)"
      echo "replace the content of file in latest git commit"
  elif [ $# -eq "2" ]; then
      git diff-tree --no-commit-id --name-only -r HEAD|xargs perl -pi -e "s/$1/$2/g"
  elif [ $# -eq "3" ]; then
      git diff-tree --no-commit-id --name-only -r $1|xargs perl -pi -e "s/$2/$3/g"
  fi
}

[ $(uname -s | grep -c CYGWIN) -eq 1 ] && OS_NAME="CYGWIN" || OS_NAME=`uname -s`
# xclip has some problem with my emacs, so I use xsel for everything
function pclip() {
    if [ $OS_NAME == CYGWIN ]; then
        putclip $@;
    elif [ $OS_NAME == Darwin ]; then
        pbcopy $@;
    else
        if [ -x /usr/bin/xsel ]; then
            xsel -ib $@;
        else
            if [ -x /usr/bin/xclip ]; then
                xclip -selection c $@;
            else
                echo "Neither xsel or xclip is installed!"
            fi
        fi
    fi
}

# search the file in root directory of git repository, pop up dialog let you choose the path,
# then put the full path in clipboard
function gg()
{
    local cli=`find $(git rev-parse --show-toplevel) -type f -iname '*'$*'*'|percol`
    echo -n ${cli}|pclip
    echo ${cli}
}

alias ge='grep -rsn --exclude=TAGS --exclude=tags --exclude=GTAGS --exclude-dir=.svn --exclude-dir=.sass-cache --exclude-dir=.cache  --exclude-dir=.cvs --exclude-dir=.git --exclude-dir=.hg --exclude=\*.swp --exclude=\*~ --color=auto'
function ggs()
{
    local cli=`ge -l $* $(git rev-parse --show-toplevel)/*|percol`
    echo -n ${cli} |pclip;
    echo ${cli}
}

I do lots of git stuff under shell, so I'm heavly dependent on below bash tools,

  • fasd to change current directory quickly
  • percol to filter the text from stdin interactively
Comments powered by Disqus