2015-09-06  git  web 

git pushでWebページをデプロイする手順メモ

参考にしたWebページはこちらです。

以下の手順は、このWebページを参考にして自分なりになぞっただけです。

リポジトリ用意

[remote: ~] $ mkdir hello.git
[remote: ~/hello.git] $ cd hello.git
[remote: ~/hello.git] $ git init --bare
[remote: ~/hello.git] $ cd

そこへPushする

[local: ~] mkdir hello
[local: ~] cd hello
[local: ~/hello] git init
[local: ~/hello] echo 'Hello' > index.html
[local: ~/hello] git add .
[local: ~/hello] git commit -m "Initial commit."
[local: ~/hello] git remote add origin ssh://USERNAME@MYSERVER:/home/USERNAME/hello.git
[local: ~/hello] git push origin master
[local: ~/hello] git remote -v
origin    ssh://USERNAME@MYSERVER:/home/USERNAME/hello.git (fetch)
origin    ssh://USERNAME@MYSERVER:/home/USERNAME/hello.git (push)

Clone

[remote: ~] $ git clone ~/hello.git hello.hyuki.net
[remote: ~] $ cd hello.hyuki.net
[remote: ~/hello.hyuki.net] $ cat index.html
Hello

編集してPush

[local: ~/hello] vi index.html
[local: ~/hello] cat index.html
<!DOCTYPE html>
<h1>Hello</h1>
[local: ~/hello] git add .
[local: ~/hello] git commit -m "Add doctype."
[local: ~/hello] git push

手動でPull

[remote: ~/hello.hyuki.net] $ git pull
[remote: ~/hello.hyuki.net] $ cat index.html
<!DOCTYPE html>
<h1>Hello</h1>

post-receiveを準備

[remote: ~/hello.hyuki.net] $ cd ~/hello.git/hooks
[remote: ~/hello.git/hooks] $ cp post-receive.sample post-receive
[remote: ~/hello.git/hooks] $ vi post-receive
[remote: ~/hello.git/hooks] $ cat post-receive
#!/bin/sh

cd /home/USERNAME/hello.hyuki.net/
git --git-dir=.git pull
[remote: ~/hello.git/hooks] $ cd

さらにPushする

[local: ~/hello] vi index.html
[local: ~/hello] git add .
[local: ~/hello] git commit -m "Add body."
[local: ~/hello] git push

今度は手動でPullしなくても更新されている

[remote: ~/hello.hyuki.net] $ cat index.html
<!DOCTYPE html>
...
<body>
<h1>Hello</h1>
</body>
</html>
[remote: ~] $ cd

Webサーバをセットアップする

[remote: ~/hello.hyuki.net] $ sudo vi /etc/httpd/conf/httpd.conf
[remote: ~/hello.hyuki.net] $ sudo /etc/rc.d/init.d/httpd restart

ふだんのデプロイ

[local: ~/hello] vi index.html (編集やファイル追加)
[local: ~/hello] git add .
[local: ~/hello] git commit -m "今回の変更の説明"
[local: ~/hello] git push
 2015-09-06  git  web