前提条件
・Gitインストール済みであること。 |
・Git Bashを使用する。 |
・Windows PC 1台で、疑似的に[クライアント側リポジトリ]と[サーバ側リポジトリ]を作成する。 |
作成リポジトリについて
以下リポジトリを作成するための操作を記述します。
クライアント側リポジトリ
C:\GitRepo\local\sampleCommonForDev
(共通機能開発用)
※説明で以下は省略します。
C:\GitRepo\local\sampleOnlineForDev | オンライン機能開発用 |
C:\GitRepo\local\sampleBatchForDev | バッチ機能開発用 |
C:\GitRepo\local\sampleBatchShellForDev | バッチ機能開発用(Shell) |
C:\GitRepo\local\sampleCommonForRelease | 共通機能リリース用 |
C:\GitRepo\local\sampleOnlineForRelease | オンライン機能リリース用 |
C:\GitRepo\local\sampleBatchForRelease | バッチ機能リリース用 |
C:\GitRepo\local\sampleBatchShellForRelease | バッチ機能リリース用(Shell) |
サーバ側リポジトリ
C:\GitRepo\server\sampleCommonForDevBare.git | 共通機能開発用(ベアリポジトリ) ※”.git“を付ける |
C:\GitRepo\server\sampleCommonForDev | 共通機能開発用 |
※説明で以下は省略します。
C:\GitRepo\server\sampleOnlineForDevBare.git | オンライン機能開発用(ベアリポジトリ) |
C:\GitRepo\server\sampleBatchForDevBare.git | バッチ機能開発用(ベアリポジトリ) |
C:\GitRepo\server\sampleCommonForReleaseBare.git | 共通機能リリース用(ベアリポジトリ) |
C:\GitRepo\server\sampleOnlineForReleaseBare.git | オンライン機能リリース用(ベアリポジトリ) |
C:\GitRepo\server\sampleBatchForReleaseBare.git | バッチ機能リリース用(ベアリポジトリ) |
C:\GitRepo\server\sampleOnlineForDev | オンライン機能開発用 |
C:\GitRepo\server\sampleBatchForDev | バッチ機能開発用 |
C:\GitRepo\server\sampleCommonForRelease | 共通機能リリース用 |
C:\GitRepo\server\sampleOnlineForRelease | オンライン機能リリース用 |
C:\GitRepo\server\sampleBatchForRelease | バッチ機能リリース用 |
クライアント側準備作業
ディレクトリ作成&移動、テスト用ファイル作成
$ pwd
/c/GitRepo/local
$ mkdir sampleCommonForDev
$ cd sampleCommonForDev
$ echo 'Hello local file.' > index.html

non-bareリポジトリ(開発作業用)作成、コミット対象追加(テスト用ファイル)
$ pwd
/c/GitRepo/local/sampleCommonForDev
$ git init
$ git add .

コミット
$ git commit -m '1st commit.'

サーバ側準備作業
ディレクトリ作成&移動
$ pwd
/c/GitRepo/server
$ mkdir sampleCommonForDevBare.git
$ cd sampleCommonForDevBare.git
bareリポジトリ(作業ディレクトリを持たない)を共有オプションを付けて作成
$ pwd
/c/GitRepo/server/sampleCommonForDevBare.git
$ git init --bare --shared

クライアントからサーバ側ベアリポジトリにpush
リモート接続用エイリアス名(origin)の追加
$ pwd
/c/GitRepo/local/sampleCommonForDev
$ git remote add origin /c/GitRepo/server/sampleCommonForDevBare.git
(サーバ指定時)
$ git remote add origin ssh://serverusername@192.168.xxx.xxx:/c/GitRepo/server/sampleCommonForDevBare.git
リモート接続情報の確認
$ git remote -v
origin C:/GitRepo/server/sampleCommonForDevBare.git (fetch)
origin C:/GitRepo/server/sampleCommonForDevBare.git (push)
サーバ側リポジトリにpush
$ git push origin master

サーバ側ベアリポジトリの確認
ログの確認
$ pwd
/c/GitRepo/server/sampleCommonForDevBare.git
$ git log
ログの確認終了(“q”を入力)
:
または
(END)
が表示された時
作業ディレクトリ(ソース)が存在しないことの確認
$ ls

サーバ側リポジトリ(SI作業用)の作成
操作ディレクトリ確認
$ pwd
/c/GitRepo/server
non-bareリポジトリ(SI作業用)をクローン作成
$ git clone sampleCommonForDevBare.git sampleCommonForDev
non-bareリポジトリ(SI作業用)の中身を確認
$ cd sampleCommonForDev
$ ls
index.html
$ cat index.html

クライアント側でのファイル修正
操作ディレクトリ確認
$ pwd
/c/GitRepo/local/sampleCommonForDev
ファイル修正
$ echo 'Hello world!' > index.html
コミット
$ git commit -m '2nd commit.'
サーバ側へpush
$ git push origin master

サーバ側での確認
ログの確認(ベアリポジトリ)
$ pwd
/c/GitRepo/server/sampleCommonForDevBare.git
$ git log

bareリポジトリ(SI作業用)に取り込み
$ pwd
/c/GitRepo/server/sampleCommonForDev
$ git pull origin master
または
$ git fetch origin master
$ git merge origin/master
※pull = fetch + merge
$ ls
