My git tips...

Ok, so a handy meme is loose: Handy Git tips. We even had a crazy anatidae requesting us to post this to the Git wiki whatever we send on this regard to our personal blogs.
Following Damog's post, I will also put my .bashrc snippet:

  1. parse_git_branch() {
  2. branch=`git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`
  3. if [ ! -z "$branch" ]
  4. then
  5. if ! git status|grep 'nothing to commit .working directory clean' 2>&1 > /dev/null
  6. then
  7. branch="${branch}*"
  8. mod=`git ls-files -m --exclude-standard|wc -l`
  9. new=`git ls-files -o --exclude-standard|wc -l`
  10. del=`git ls-files -d --exclude-standard|wc -l`
  11. if [ $mod != 0 ]; then branch="${branch}${mod}M"; fi
  12. if [ $new != 0 ]; then branch="${branch}${new}N"; fi
  13. if [ $del != 0 ]; then branch="${branch}${del}D"; fi
  14.  
  15. fi
  16. fi
  17. echo $branch
  18. }

This gives me the following information on my shell prompt:

  • The git branch where we are standing
  • If it has any uncommitted changes, a * is displayed next to it
  • If there are changes not checked in to the index, M (modified), N (new) or D (deleted) is displayed, together with the number of files in said condition. i.e.,

    Sometimes, entering a very large git tree takes a second or two... But once it has run once, it goes on quite smoothly.
    Of course, I still have this also in .bashrc - but its funcionality pales in comparison:
    1. get_svn_revision() {
    2. if [ -d .svn ]
    3. then
    4. svn info | grep ^Revision | cut -f 2 -d ' '
    5. fi
    6. }

    I am sure it can be expanded, of course - but why? :)