Archive

Archive for October, 2011

Git on Mac

October 12th, 2011 No comments

Two things that I have found really useful when working with Git on a mac:

First autocomplete in terminal. When I started using Git I used the client program Github for mac, but because I found it too buggy i switched to only using the terminal. This also gives you a better understanding of what's going on. But the problem was I could not autocomplete git commands. Luckily this was really simple to add this feature.

Download this script and save it as git-completion.bash

https://github.com/git/git/raw/master/contrib/completion/git-completion.bash

Add the file to your .bash_profile

source ~/git-completion.bash

 

Then make some shortcut alias in .gitconfig

1
[Alias]

1
st = status

1
co = checkout

1
br = branch

1
ci = commit

1
rb = rebase

Remember to restart you terminal (or open a new window).

Another very useful thing is to show you working branch in the prompt. Here you just have to change your PS1 in .bash_profile. There are many ways to do this and some really nice ones are shown here:

http://asemanfar.com/Current-Git-Branch-in-Bash-Prompt

I don't see a reason to put the hostname (computername) in the prompt, so after some modification I ended up with this:

export PS1="\[\033[1;33m\]\u\[\033[01;34m\] \w \[\033[31m\]\`git branch 2> /dev/null | grep -e ^* | sed -E  s/^\\\\\\\\\*\ \(.+\)$/\(\\\\\\\\\1\)\ /\`\[\033[37m\]$\[\033[00m\] "
Categories: Bash, Git, mac Tags: ,