Hatena::ブログ(Diary)

femocoの日記

2009-07-10

githubに初めてリポジトリを作成する際のチュートリアル

14:31

SSH公開鍵を作成する

使用しているパソコンにsshの公開鍵が無い場合は、新たに作成します。

rsaまたはdsaの鍵ペアを既に持っている場合は、このステップは省略します。

cd ~/.ssh
ssh-keygen
Generating public/private rsa key pair.  
Enter file in which to save the key (/Users/username/.ssh/id_rsa): # press enter here  
Enter passphrase (empty for no passphrase): # type in your passphrase here  
Enter same passphrase again: # type your passphrase again  
Your identification has been saved in /Users/username/.ssh/id_rsa.  
Your public key has been saved in /Users/username/.ssh/id_rsa.pub.  
The key fingerprint is:  
30:93:77:c6:97:af:61:82:dc:ea:9b:6b:67:d4:1b:61 user@host  

公開鍵(ここではid_rsa.pubという名前のファイルとします)の内容を以下のようにしてクリップボードにコピーします。

cat id_rsa.pub | pbcopy

githubのアカウントのページを開き、「SSH Public Keys」の項目以下の「add another public key」をクリックし、コピーしてある公開鍵の内容をペーストします。

githubリポジトリを作成する

http://github.com/repositories/newのページを開き、新しいリポジトリを作成します。

project name、description、homepage urlを必要に応じて記入し、Create Repositoryをクリックして新規リポジトリを作成します。

project name: sample

description: my sample repository

homepage url: http://d.hatena.ne.jp/femoco

リポジトリの作成が完了すると、githubが次の作業を指示してくれます。

以下のように表示されました。

Global setup:
  Download and install Git
  git config --global user.name "FeMoCo"
  git config --global user.email email@address.hoge
        
Next steps:
  mkdir sample
  cd sample
  git init
  touch README
  git add README
  git commit -m 'first commit'
  git remote add origin git@github.com:femoco/sample.git
  git push origin master

この指示に従い、リポジトリに載せるためのディレクトリを作成していきます。

ここでは、~/code/sampleというディレクトリ以下にファイルを置いていることにします。

cd ~/code
mkdir sample
cd sample
git init
touch README
git add README
git commit -m "first commit"
git remote add github git@github.com:femoco/sample.git
git push github master
ここで公開鍵に対するパスフレーズを訊かれるので、設定したパスフレーズを入力します。

これで、作成したリポジトリにREADMEのみがpushされました。

githubをリモートリポジトリとして設定する

cd ~/code/sample
emacs .git/config

作成したconfigファイルを以下のように編集します。

[core]
	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true
	ignorecase = true
[remote "github"]
	url = git@github.com:femoco/sample.git
	fetch = +refs/heads/*:refs/remotes/origin/*
	push = refs/heads/master:refs/heads/master

githubにpushする

sampleディレクトリに何か新しいファイルを作成して、githubにpushしてみます。

cd ~/code/sample
emacs sample.txt

sample.txtを以下のように編集してみます。

This is a sample text for github tutorial.

commitし、以下のようにpushします。

git push github master

以上で、githubにpushすることが出来ました。

トラックバック - http://d.hatena.ne.jp/femoco/20090710/1247203900