Forked from https://github.com/trey, credit for a lot of the ideas go to Trey! I mainly modified the Bash Fanciness area to be more to my liking.
brew install git bash-completion
Configure things:
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git config --global alias.co checkout
git config --global apply.whitespace nowarn
Setup an SSH key
ssh-keygen
Hit return a couple of times -- leave password blank if you want.
cat ~/.ssh/id_rsa.pub | pbcopy
Paste that code into your settings page on your repository host(s).
Get happy Git colors. Paste the following into your ~/.gitconfig
file:
[color]
branch = auto
diff = auto
status = auto
[color "branch"]
current = yellow reverse
local = yellow
remote = green
[color "diff"]
meta = yellow bold
frag = magenta bold
old = red bold
new = green bold
[color "status"]
added = yellow
changed = green
untracked = cyan
Create a ~/.gitexcludes
file and paste in this:
.DS_Store
There, now you don't have to ignore that every time.
Add the following to your ~/.bash_profile
or ~/.bashrc
:
source /usr/local/etc/bash_completion.d/git-completion.bash
source /usr/local/etc/bash_completion.d/git-prompt.sh
GIT_PS1_SHOWDIRTYSTATE=true
GIT_PS1_SHOWCOLORHINTS=true
black=$(tput setaf 0)
red=$(tput setaf 1)
green=$(tput setaf 2)
yellow=$(tput setaf 3)
blue=$(tput setaf 4)
magenta=$(tput setaf 5)
cyan=$(tput setaf 6)
white=$(tput setaf 7)
reset=$(tput sgr0)
if [ $(id -u) -eq 0 ];
then
PROMPT_COMMAND='__git_ps1 "\[$red\]\u@\h:\[$cyan\]\w\[$reset\]" "\\\$ "'
else
PROMPT_COMMAND='__git_ps1 "\[$green\]\u@\h:\[$cyan\]\w\[$reset\]" "\\\$ "'
fi
export PROMPT_COMMAND
That will add tab auto-completion for Git branches, display the current branch on your prompt, and show a '*' after the branch name if there are unstaged changes in the repository, and a '+' if there are staged (but uncommitted) changes. It will look something like this:
[user@computer ~/Sites/example.com (master*)]$
If you want to have a different email address for a particular project (a personal project on your work computer, perhaps?), just run this command inside that project's folder:
git config user.email "you@example.com"
It's the same command as before, this time just omitting the --global
.