"When the best way is also the simplest,
laziness and diligence are indistinguishable."
- Probably
$ git init --bare reponame.git
Bare repos are usually to be checked-out to various locations
by multiple users. This is the part we want to automate.
$ cd repos
$ git init --bare myproj.git
$ vim myproj.git/hooks/post-receive
#!/bin/sh
GIT_WORK_TREE=webroot/www.myproj.com
git checkout -f
$ chmod +x myproj.git/hooks/post-receive
$ git remote add origin ssh://me.sharedhost.com/home/me/repos/myproj.git
Note:
You can't clone the new repo in order to set
up your remotes automatically (like github).
There needs to be some data in it first.
$ git add .
$ git commit -m "My rad changes"
$ git push origin master
Well, this is pretty easy. Just do the same thing
twice, then bind them with different aliases.
$ git remote add live ssh://me.sharedhost.com/home/me/repos/myproj.git
$ git remote add staging ssh://me.someotherhost.com/home/me/repos/myproj.git
$ git push live master
$ git push staging master
Done.
#!/bin/sh
LIVE_DIR="webroot/myproj"
TEST_DIR="webroot/staging/myproj"
# Scrape branch name from incoming arguments
BRANCH=$( echo $1 | awk '{ split ($1,a,"/") } END { print a[3]; }' )
# Set checkout directory based on branch name
case $BRANCH in
"master") CHECKOUT_DIR="$LIVE_DIR" ;;
"staging") CHECKOUT_DIR="$TEST_DIR" ;;
esac
# Checkout this branch to appropriate directory
GIT_WORK_TREE="$CHECKOUT_DIR"
git checkout $BRANCH -f
$ git remote add origin ssh://me.sharedhost.com/home/me/repos/myproj.git
Always do new work on a dev branch
$ git checkout -b staging
. . .
$ git add . && git commit -m "My rad changes"
Preview on staging server
$ git push origin staging
Merge into master branch when ready
$ git checkout master
$ git merge staging
Push to live server from master branch
$ git push origin master
For sufficiently complex projects, you'll need...
(probably Capistrano)
$ git config http.receivepack true
eg: Vim:
nnoremap <leader>gc :!git add . && git commit -m ""<left>
nnoremap <leader>gp :!git push