Git 共有リポジトリ運用の始め方 (bareリポジトリ)

■このエントリの前提条件
・gitインストール済み
・複数サーバー(svrA,svrB)上にそれぞれリポジトリあり
・svrAにbareリポジトリをつくる
・srvAにはSSHでアクセスできる
・srvAのローカルリポジトリには既にファイルがコミットされている

共有リポジトリ設定

【srvA】
■bareリポジトリを作成

$ mkdir ~/testapp.git
$ cd ~/testapp.git
$ git --bare init

■既存のローカルリポジトリ(~/testapp) を共有リポジトリへpush

$ cd ~/testapp
$ git push ~/testapp.git master

■今後変更していくローカルリポジトリをcloneで作成

$ mkdir ~/testapp_use
$ cd ~/testapp_use
$ git clone ~/testapp.git testapp

【srvB】
■srvAの共有リポジトリをclone (sshを利用)

$ cd ~
$ git clone srvA_user_name@srvA_ip_address:testapp.git testapp
srvA_user_name@srvA_ip_address's password: xxxxx

srvAの変更内容をpush後、srvBでpull
【srvA】
■ファイルの内容を変更、コミット

$ cd ~/testapp_use/testapp
$ vi readme.txt
$ git add .
$ git commit -m "fix on srvA"
$ git push

【srvB】
■変更内容をpull

$ cd ~/testapp
$ git pull

srvBの変更内容をpush後、srvAでpull
【srvB】
■ファイル内容を変更

$ cd ~/testapp
$ vi readme.txt
$ git add .
$ git commit -m "fix on srvB"
$ git push
srvA_user_name@srvA_ip_address's password: xxxxx

【srvA】
■変更内容をpull

$ cd ~/testapp_use/testapp
$ git pull