LoginSignup
14
15

More than 5 years have passed since last update.

`git push` したら VPSサーバーと Bitbucketの両方に反映させる方法

Last updated at Posted at 2013-10-23

この2つのまとめ+αです。

http://qiita.com/ironsand/items/cad715c0630d3e9f2df3
http://qiita.com/ironsand/items/cad715c0630d3e9f2df3

条件

Bitbucket
CentOS(さくらのVPS)

やること

  1. [ローカル] -git push-> [VPS の ベアリポジトリ]
  2. [VPS の ベアリポジトリ] <-git pull- [VPS のファイルを配置したい場所]
  3. [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

とまあこんな感じです。

14
15
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
15