LoginSignup
28

More than 5 years have passed since last update.

メモ: Gitリモートリポジトリにpushして自動更新してもらう方法

Last updated at Posted at 2014-01-08

リポジトリの新規作成

1. サーバーでbareリポジトリを作成

bareリポジトリを作成
# mkdir -p /opt/repo/src.git
# cd /opt/repo/src.git
# git init --bare

2. サーバーでbareリポジトリをclone

リポジトリのクローンを作成
# cd /opt
# git clone /opt/repo/src.git

3. ローカルでサーバーのbareリポジトリをclone

リポジトリのclone
# git clone ssh://192.168.11.11/opt/repo/src.git

4. ローカルでなにかコミットする

何かファイルを作ってコミットしておく。
# cd src
# date > memo.txt
# git add memo.txt && git commit -m "memo"

5. ローカルでサーバーにpush

リモートリポジトリにpush
# git push --all

自動更新用にHookスクリプトを作成

1. サーバーで作業

# cd /opt/repo/src.git/hooks/
# cp -a post-receive.sample post-receive

2. サーバーでpost-receiveを編集

post-receive
+ cd /opt/src
+ git --git-dir=.git pull

3. ローカルからサーバーにコミットをpushする

何かファイルを作ってコミットしておく。
# echo "hoge" > memo.txt
# git add memo.txt && git commit -m "hoge"
リモートリポジトリにpush
# git push

4. 変更を確認する

これで、/opt/src/memo.srcの内容が自動で更新される。

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
28