Skip to content

Adding Git profile to Mac Terminal

Edit the .bash_profile to add the Git Profile

cd ~
vi .bash_profile

# Setting Colors
c_cyan=`tput setaf 6`
c_red=`tput setaf 1`
c_green=`tput setaf 2`
c_sgr0=`tput sgr0`

# Branch Colors
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 -n $color
}

# Changing Branch color using function
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
}

# Setting the terminal
PS1='\u@[${c_cyan}\][\h]\[${c_red}\]{:\W}\[${c_sgr0}\]\[\[$(branch_color)\]$(parse_git_branch)\[${c_sgr0}\]$'

Adding Git Alias on mac

vi .bash_profile

alias gs='git status'
alias ga='git add .'
alias gcm='git commit -m'
alias gpusho='git push origin master'
alias gpullo='git pull origin master'
alias rmfolder='git rm -r'
alias rmfile='git rm'
alias gr='git reset'

Shashi View All

-== Superman ==-

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: