Tag/git

Macにgitをインストールしてそのままgithubにも登録

まずはMacにgitをインストールしてみる

MacPortsでインストール

# sudo port install git-core +svn

エラーが出た

# Error: Target org.macports.activate returned: Image error:
/opt/local/lib/perl5/5.8.8/darwin-2level/auto/List/Util/Util.bs is
being used by the active perl5.8 port.  Please deactivate this port
first, or use the -f flag to force the activation.
# Error: The following dependencies failed to build:
p5-scalar-list-utils p5-svn-simple subversion-perlbindings apr
apr-util cyrus-sasl2 neon serf subversion p5-term-readkey rsync popt
# Error: Status 1 encountered during processing.

そういえばportのアップデートなども行っていなかったな・・・ちゃんとやろう。

自分の環境では「/usr/local/src/localports」に設定してあったので、そこまで移動してportindex

# cd /usr/local/src/localports
# sudo portindex

次にアップデートを行った

# sudo port -d selfupdate

# 既にgitをインストールされている場合はdeactivateする # インストールされていないと下記のようにエラーが出る

# sudo port deactivate git-core
# Error: port deactivate failed: Registry error: git-core not
registered as installed & active.

ではインストール

# sudo port install git-core +gitweb +svn
.........
--->  Installing git-core @1.6.3.3_0+doc+gitweb+svn
--->  Activating git-core @1.6.3.3_0+doc+gitweb+svn
--->  Cleaning git-core

インストール完了。これで準備が整ったので、そのままgithubに登録したのでその手順をメモメモ。

ここからはgithubへの登録手順

githubのURLはこちらgithub.comからアクセス可能
1. ユーザー登録
まずはユーザー登録するのだが、ここで「SSH Public Keys」を登録する項目があるのだが未入力でスルーした。
# 後で登録も出来るし追加もで出来るので問題無い。
登録すると自分のホーム画面となる。
github01
github01 posted by (C)kishir
画面にある「Create a Repository」からレポジトリを作成する。リンクをクリックするとレポジトリの作成画面となる。
ここで入力するのはとりあえず「Project Name」だけでOK。
github02
github02 posted by (C)kishir
そうするとgitのレポジトリが作成されて、設定方法が表示されるので指示に従って行う。
github03
github03 posted by (C)kishir

2. 「SSH Public Keys」の作成と登録 (ここからはMacでの作業

# 今回は公開鍵を「id_rsa」では無く「github_id_rsa」で行っています。

# 参考ページはhttp://github.com/guides/providing-your-ssh-key#macosx-3

# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/tom/.ssh/id_rsa): ← ファイル名はid_rsaでOK? いや今回は違う名前が良いので、github_id_rsaを打ってエンター
Enter passphrase (empty for no passphrase): ← パスワードの設定
Enter same passphrase again: ← 上記のパスワードを再入力
Your identification has been saved in /Users/.ssh/github_id_rsa.
Your public key has been saved in /Users/.ssh/github_id_rsa.pub.

これで公開鍵のペアが完成したので、そいつらを「.ssh」以下に移動

# mv github_id_rsa .ssh/
# mv github_id_rsa.pub .ssh/

次に先ほど作成したgithub_id_rsaの中身をクリップボードへコピーする

# cat github_id_rsa.pub | pbcopy

これでコピーされているはずなので、そのままgithubサイトの公開鍵設定のテキストエリアへ貼り付ける。

# 公開鍵は会社用や自宅用など複数の設定が可能

configファイルの設定は「.ssh/config」 に下記を追記する。

これはホスト名が「github.com」の場合は、この設定で行うよ!ってことがつらつらと書かれている。 # githubサイトに記載されている

Host github.com
 User git
 Port 22
 Hostname github.com
 IdentityFile ~/.ssh/github_id_rsa
 TCPKeepAlive yes
 IdentitiesOnly yes

3. レポジトリの作成

# git config --global user.name 'ユーザー名'
# git config --global user.email '登録メールアドレス'

次にMacのローカル上でのgitの作業ディレクトリを作成

# mkdir jqplugin
# cd /Users/projects/workspace/プロジェクト名/
# touch README
# git init
Initialized empty Git repository in /Users/projects/workspace/プロジェクト名/.git/
# ls -la
total 8
drwxr-xr-x  4 user group   136 Jul 30 15:55 ./
drwxr-xr-x  3 user group   102 Jul 30 15:55 ../
drwxr-xr-x  9 user group   306 Jul 30 15:55 .git/
-rw-r--r--  1 user  group  1379 Jul 30 15:54 READEME

.gitというディレクトリが出来ているの確認してから、 ファイルをadd(追加)してステータスを確認してみる

# git add READEME
# git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#       new file:   READEME
#

確認が出来たのでコミットしてみる

# git commit -m "こみっとてすと"
[master (root-commit) 487cdff] こみっとてすと
1 files changed, 28 insertions(+), 0 deletions(-)
create mode 100644 READEME
# git remote add original git@github.com:ユーザー名/作成したディレクトリ名.git
# git push original master
Counting objects: 6, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (6/6), 1.17 KiB, done.
Total 6 (delta 0), reused 0 (delta 0)
To git@github.com:ユーザー名/作成したディレクトリ名.git
* [new branch]      master -> master

これで完了したので、最後にgithubで確認してみる。

あー疲れた。結構長く書いたな。まぁーたまにはいっかなぁー :-)

Posted at: 
2009/07/31 22:20:45
0 Comments
0 TrackBacks
Tags: 
git
Mac
Trackback: 
http://kishi-r.com/2009/07/31/mac_git/trackback/

あわせて読みたい 人気ブログランキング - kishi-r.com track feed

Categories