2010年11月9日火曜日

Dropbox に gitレポジトリを作成する

1.
Dropbox フォルダ内に gitレポジトリ用のフォルダを作成する。
cd ~/Dropbox
mkdir repository

2.
上記フォルダ内に、[プロジェクト名].git というフォルダを作成して init する。
cd repository
mkdir ProjectName.git
cd ProjectName.git
git --bare init

--bare
Create a bare repository. If GIT_DIR environment is not set, it is set to the current working directory. *1

裸のリポジトリ(bare repository)
裸のリポジトリとは、通常 .git の拡張子を持つ ディレクトリ で、 リビジョン管理下にあるチェックアウトしたファイルをローカルに持たないディレクトリです。 通常 .git サブディレクトリ に隠れている git の管理ファイル全てが repository.git ディレクトリに直接存在し、 他のファイルは存在せず、チェックアウトもされていません。 通常、公開リポジトリを出版する人は、裸のリポジトリを作成します。*2

3.
既存のソースを追加するためには、そのプロジェクト上で以下のコマンドを実行する。
cd ~/develop/OldProject
git init
git add . // 全てのファイルを追加する
git commit
git push ~/Dropbox/repository/ProjectName.git master
git remote add origin ~/Dropbox/repository/ProjectName.git

4.
ファイルを更新した後、以下のように更新したファイルの addとcommitを行い、さらに ローカルレポジトリ(既存プロジェクト)をリモートレポジトリ(Dropbox に作成したレポジトリ)へ push する。
git add ~/develop/OldProject/oldfile.h // 変更を全て含む場合、git add --a
git commit // コメントを追加する場合は、git commit -m "(コメント入力)"
git push ~/Dropbox/repository/ProjectName.git master //git push origin master でも可

参考:
*1
git-init(1) Manual Page

*2
Chapter11. GIT用語集 裸のレポジトリ