この2つのまとめ+αです。
http://qiita.com/ironsand/items/cad715c0630d3e9f2df3
http://qiita.com/ironsand/items/cad715c0630d3e9f2df3
条件
Bitbucket
CentOS(さくらのVPS)
やること
- [ローカル] -
git push
-> [VPS の ベアリポジトリ] - [VPS の ベアリポジトリ] <-
git pull
- [VPS のファイルを配置したい場所] - [VPS のファイルを配置したい場所] -
git push
-> [Bitbucket]
の3つを 1. を行うだけで後は勝手にやるように設定する。
「ベアリポジトリいらなくね?」という疑問に答えてくれる人を絶賛募集中
(Bitbucketからのhookでやる方法はpull request
用のスクリプトを外部アクセスできる形で置くのが気持ち悪かったので辞めました。)
手順
1. インストール
# git インストール
$ sudo yum -y install git git-daemon git-all
# ベアリポジトリを作成
$ mkdir -p ~/git-repos/foo.git
2. ファイルを配置したい場所もgitで初期化してBitbucket を remote origin
に追加しておく
やり方はお好きな方法でどうぞ。
一度ローカルから直接Bitbucketに上げておいて、それをclone
するのが一番簡単かな?
3. pushを受け取ったあとの処理を書くので hooks/post-receive
を編集
~/git-repos/foo.git/hooks/post-receive
pwd
cd /var/www/example.com/wp-content/themes/mytheme
pwd
git --git-dir=.git pull ~/git-repos/goo.git master
git --git-dir=.git push origin master
4. ローカルから push する
$ git init
$ git add .
$ git commit -m "initial"
$ git remote add origin ssh://username@hostname:port/home/username/git-repos/foo.git
$ git push origin master
とまあこんな感じです。