S-JIS[2016-11-28] 変更履歴
Gitのクローンを行うコマンドのメモ。
クローンは、既存のリポジトリーを複製して新しいリポジトリーを作るコマンド。
GitHub上のリポジトリーを複製して、自分のローカルマシン上に新しいリポジトリーを作るのによく使用する。
既存のリポジトリーをコピーして新しいリポジトリーを作ることが出来る。
$ cd /tmp/from $ git clone project /tmp/to/project
ただし、この方法だとmasterブランチのみになる(他のブランチはコピーされない(リモートのブランチとしては認識される))。
$ git branch -a * master remotes/origin/HEAD -> origin/master remotes/origin/master remotes/origin/wip/test
ブランチごとコピーするには以下のようにする。
$ cd /tmp/from $ ls -a project/ . .. .git test.txt
$ git clone --bare project /tmp/to/project/.git/
$ cd /tmp/to/project $ ls -a . .. .git
$ git init Reinitialized existing Git repository in /tmp/to/project/.git/ $ git reset --hard HEAD is now at e3320c6 Added test.txt $ ls -a . .. .git test.txt $ git branch -a * master wip/test
$ git remote -v origin /tmp/from/project (fetch) origin /tmp/from/project (push) $ git remote rm origin
「git clone --bare」の代わりに「git clone --mirror」でも出来るが、違いはよく分からない^^;
ただし、ミラーだと「git remote rm」の際に警告が出る。