Git branch in Mac OSX bash prompt

I tried using the same changes for my linux boxes on my macbook air and they didn't work, so I googled around and stumbled upon using this instead:

 

 

c_cyan=`tput setaf 6`
c_red=`tput setaf 1`
c_green=`tput setaf 2`
c_sgr0=`tput sgr0`
parse_git_branch (){
    if git rev-parse --git-dir >/dev/null 2>&1
    then
        gitver=$(git branch 2>/dev/null| sed -n '/^\*/s/^\* //p')
    else
        return 0
    fi
    echo -e $gitver
}
branch_color (){
    if git rev-parse --git-dir >/dev/null 2>&1
    then
        color=""
    if git diff --quiet 2>/dev/null >&2 
    then
        color="${c_green}"
    else
        color=${c_red}
    fi
    else
        return 0
    fi
    echo -ne $color
}

#Branch First
#PS1='[\[$(branch_color)\]$(parse_git_branch)\[${c_sgr0}\]] \u@\[${c_red}\]\w\[${c_sgr0}\]: '
#Branch Last
PS1=' \u@\[${c_red}\]\w\[${c_sgr0}\]: [\[$(branch_color)\]$(parse_git_branch)\[${c_sgr0}\]] '

 

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

 

Git: Prepare your repository – step 1

 

Here I’ll explain how you can create a new repository for your projects and use GIT for your version control needs.
 
 
For this, I’ll assume everything is already installed (git and stuff). This also assumes you’re using an Operating System and not the Vermont thing.
 
Replace “example.com” with your own domain.
 
1. Create a base repository
 
$ mkdir example.com && cd example.com

$ git init
 
 
2. Create a standard .gitignore file
 
$ nano .gitignore
 
—————————-
cgi-bin/*

upload/

.idea/*

# Compiled source #

###################

*.com

*.class

*.dll

*.exe

*.o

*.so

# Packages #

############

# it's better to unpack these files and commit the raw source

# git has its own built in compression methods

*.7z

*.dmg

*.gz

*.iso

*.jar

*.rar

*.tar

*.zip

# Logs and databases #

######################

*.log

*.sql

*.sqlite

# OS generated files #

######################

.DS_Store*

ehthumbs.db

Icon?

Thumbs.db
—————————-
 
3. Add and commit the file to your local repository.
$ git add .gitignore

$ git commit -m "Added standard gitignore file"
 
4. Prepare your local repository for transportation:
$ cd ..

$ git clone --bare example.com example.com.git

$ touch example.com.git/git-daemon-export-ok
 
5. Copy it to your server
$ scp -r example.com.git SERVER:~/PATH_ON_THE_SERVER/example.com.git
 
6. Finish preparing your repository on the server:
 
$ ssh SERVER

$ cd ~/PATH_ON_THE_SERVER/example.com.git

$ git --bare update-server-info

$ cd hooks

$ mv post-update.sample post-update

$ chmod a+x post-update
 
From this point on, you should be able to clone your repository and start working.
 
Drop me a line if this does not work for you, and I'll be glad to try and help.
 

 

Git::Basic settings

Add .git_completion.sh to your home directory, and add this to your .bash_profile:

 

source ~/.git_completion.sh

function parse_git_dirty {
  [[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}

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

export PS1='\h:\W$(__git_ps1 "[\[\e[0;32m\]%s\[\e[0m\]\[\e[0;33m\]$(parse_git_dirty)\[\e[0m\]]")$ '
  • IGlr