ByteNoise

Git tips

Useful things to put in ~/.gitconfig

Remember who you are

git config —global user.name "Alice Smith"
git config —global user.email "alice@example.com"

Never fast forward merges into the master or dev branches

git config —global branch.master.mergeoptions "—no-ff"
git config —global branch.dev.mergeoptions "—no-ff"

Automatically updating live and development versions of a website

On the server's bare repository, put the following in hooks/post-receive, where master and dev are the names of the branches you want Apache to see

GIT_WORK_TREE=/var/www/www.example.org git checkout master -f
GIT_WORK_TREE=/var/www/www.example.org git clean -f
GIT_WORK_TREE=/var/www/dev.example.org git checkout dev -f
GIT_WORK_TREE=/var/www/dev.example.org git clean -f

Remove files that shouldn't have been managed with Git

Such as large binary files that should be ignored by Git as they're not part of the main system, or sensitive information, or something you're not legally allowed to distribute.

git filter-branch —index-filter 'git rm -rf —cached —ignore-unmatch misc/bloody-large-file.tar' HEAD

These are simply tricks I've learnt during my years as a web developer. They may not be the best solutions. Please e-mail me any bugfixes or improvements to these examples. Thank you.