4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

gitでpushと同時にデプロイする場合の注意

Last updated at Posted at 2016-03-05

はまったのでメモ。

gitでpushと同時にデプロイする場合、以下参照。
http://qiita.com/zaburo/items/8886be1a733aaf581045#%E3%83%AA%E3%83%A2%E3%83%BC%E3%83%88%E3%83%AA%E3%83%9D%E3%82%B8%E3%83%88%E3%83%AA%E3%81%AEpost-receive%E3%82%92%E8%A8%AD%E5%AE%9A%E3%81%99%E3%82%8B

実行したいスクリプトをhoge.git/hooks/post-receiveに、実行権限付きで置けばよい。

ただ上記URLのpost-receiveスクリプトでは問題ないが、以下はうまくいかず。「fatal: Not a git repository」が出る。

post-receive
cd /var/www/html/test
git pull

これはgit pull時に$GIT_DIRが設定されており、pwdよりも優先するための模様。
http://stackoverflow.com/questions/4043609/getting-fatal-not-a-git-repository-when-using-post-update-hook-to-execut/4100577#comment24975396_4100577

そのため、以下のようにする必要あり。

post-receive(参照URL上のもの)
cd /var/www/html/test
git --git-dir=.git pull
post-receive
unset GIT_DIR
cd /var/www/html/test
git  pull
4
5
0

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
4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?