Alister West

home is where your code is ...

Git Init

Stuff to do before you run 'git init'

Setup global config

# Personal info
git config --global user.name "Alister West"
git config --global user.email "alister@alisterwest.com"

# fix first commit cause i forgot to update config.
git commit --amend --author="Alister West <alister@alisterwest.com>"

# Always rebase [1],[2] for linear history.
git config branch.autosetuprebase always

# Always rebase this master branch
git config branch.master.rebase true

# Shortcut to unstage "git unstage myfile"
git config --global alias.unstage 'reset HEAD --'

# Colours [2]
git config --global color.ui true

# On a shared account update your .bashrc with gits environment vars.
export GIT_AUTHOR_NAME="Alister West";
export GIT_AUTHOR_EMAIL="alister@alisterwest.com"

Setup bare repo config

# setup bare (master) repo
git init --bare --shared foo.git; cd foo.git
git config receive.denyNonFastforwards true

# for http(s) connections
git update-server-info
vim /etc/httpd/vhosts/mysite.ssl.com "Use GIT my_project authdomain"

# populate new bare-repo from an existing project
# http://caiustheory.com/adding-a-remote-to-existing-git-repo
git remote add --track master origin alister@example.com:/var/git/foo.git
git push origin master
git push --tags

# push EVERYTHING to a remote bare repo
# http://toroid.org/ams/git-central-repo-howto
cd mylocal_project.git
git push alister@example.com/var/git/foo.git '*:*'

Setup project config

# Setup a remote based off an existing git repo.
git init foo; cd foo
git remote add --track master origin ssh://alister@example.com:22//path/to/repos/my_project.git

Setup email notification

## myrepo.git/hooks/post-receive
#!/bin/sh
git-commit-notifier git-notifier-config.yml

## myrepo.git/git-notifier-config.yml
delivery_method: sendmail
from:            git@example.com
mailinglist:     git-myrepo@example.com
lines_per_diff:  1000
expand_css:      false

# Link with Redmine
link_files: redmine
redmine:
    path:    http://redmine.example.com
    project: myrepo
message_map:
    '#([0-9]+)([\s]|\z)': 'http://redmine.example.com/issues/\1'

Setup colors

# Nicer colors than the default
# Put in your global ~/.gitconfig
[color]
    ui = 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

Git with Bash-Completion

# gentoo/portage bash-completion
echo "dev-vcs/git webdav bash-completion" >> /etc/portage/package.use
emerge git

# Need to turn on the git option for each user..
eselect bashcomp enable git
# ... or globally
sudo eselect bashcomp enable --global git

# MacPorts bash-completion [5]
sudo port install git +svn +bash_completion
# or without re-installing git
curl https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh > ~/.git-prompt.sh

# OSX Homebrew bash-completion
brew install bash-completion
brew tap homebrew/completions
. $(brew --prefix)/etc/bash_completion


# Install
PS1="[\u@\h] \w \$(__git_ps1) \t >"
[alister@example.com] ~/myproj/  (master) 11:45:42 >

Ignore non-project files within a git repo

# $PROJECT/.gitignore
logs/
mail/
tmp/
*.swp
*.bak    
*.compiled
.DS_Store
# Sometimes we want www, sometimes not but we always want static.
www/
!www/static/

Git Initial Commit

git add .
git commit -a -m 'Initial Commit'

References

[1] http://d.strelau.net/post/47338904/git-pull-rebase-by-default

[2] http://blog.woobling.org/2009/05/git-rebase-considered-awesome.html

[3] http://kernel.org/pub/software/scm/git/docs/git-config.html

[5] http://www.mariusv.com/bash-auto-completion-in-iTerm2-osx/

[4] http://www.arthurkoziel.com/2008/05/02/git-configuration/ no worky any more.

By Alister West