Gitを使い始めて、そろそろ1年になります。
だいぶ慣れたかと思いきや、急につまずくこともあったり。
なので、整理のためにも自分なりにまとめていこうと思います。
まずは初歩的なところから。
Githubからローカルにcloneする
やり方がいくつかあるので、まとめてみました。
1. HTTPSを使う場合
一番シンプルなのがこれ。
$ git clone https://github.com/twitter/bootstrap.git
clone以下のURLは、Githubの画面上部に表示されている、
赤枠の部分をコピペすればよいです。
環境によっては、プロキシの設定が必要な場合もあるかもしれません。
export http_proxy=http://< proxy_address >:< proxy_port >/
ちなみに、HTTPS以外にも HTTP や GITプロトコルを指定してもOKみたいですね。*1
$ git clone http://github.com/twitter/bootstrap.git $ git clone git://github.com/twitter/bootstrap.git
2. SSHを使う場合
GitHubにSSH公開鍵を登録することで、SSH経由でアクセスすることができます。
後々もGithubを使って開発をするのであれば、SSH公開鍵を登録してしまった方が何かと楽かもしれません。なお、Githubアカウント必須です。
まずは、SSH鍵ペアを作成。
パスフレーズは無し、鍵ファイル名は「~/.ssh/github_rsa」とします。*2
$ ssh-keygen
Githubにログインして、[Account Settings] -> [SSH Keys] -> [Add SSH key] から、
作成した公開鍵(~/.ssh/github_rsa.pub)の内容をコピペ。
~/.ssh/config を設定。
Host github.com User git Hostname github.com PreferredAuthentications publickey IdentityFile ~/.ssh/github_rsa
github.com に接続テスト。
$ ssh git@github.com Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'github.com,207.97.227.239' (RSA) to the list of known hosts. PTY allocation request failed on channel 0 Hi akiyoko! You've successfully authenticated, but GitHub does not provide shell access. Connection to github.com closed.
テストOKなら、cloneしてみる。
$ git clone ssh://git@github.com/twitter/bootstrap.git # 「ssh://」を省略して、「:」で繋いでもOK $ git clone git@github.com:twitter/bootstrap.git
参考