前言
記錄一下自己的學習記錄。
一、安裝Git
由於mac git的地址http://code.google.com/p/git-osx-installer/被牆,被迫使用源碼安裝,源碼可以從http://kernel.org/pub/software/scm/git/下載,編譯源碼需要先安裝xcode,參考http://developer.apple.com。
編譯安裝
1、解壓
tar xjvf git-1.7.4.1.tar.tar.bz2
2. 編譯
cd git-1.7.4.1
./configure --prefix=/usr/local
make
3.安裝
sudo make install
Ok 了,which git試一下~
二、設置SSH
github使用SSH鏈接,需要設置SSH
1.檢查SSH key
cd ~/.ssh
2.備份已有的key,(如果有的話)
mkdir key_backup
mv id_rsa* key_backup
3.生成SSH key
$ ssh-keygen -t rsa -C [email protected]
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/jiangbo/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in yes.
Your public key has been saved in id_rsa.pub.
The key fingerprint is:
fb:c4:b0:e0:47:fd:be:e0:fb:ea:73:ef:a8:29:d5:22 [email protected]
The key’s randomart image is:
+–[ RSA 2048]—-+
| |
| |
| |
| . |
| . S .. |
| . oE=o.. |
| . +o+.. |
| ..+.+.. |
| oOB=+o |
+—————–+
4.將SSH key添加到GitHub
登錄到GitHub頁面,Account Settings->SSH Public Keys->Add another key
將生成的key(id_rsa.pub文件)內容copy到輸入框中,save。
5.測試鏈接
$ ssh [email protected]
The authenticity of host ‘github.com (207.97.227.239)’ can’t be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? yes
PTY allocation request failed on channel 0
Hi jiang-bo! You’ve successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.
別擔心,這是正常情況。
三、設置個人信息
$ git config –global user.name “Ericky”
$ git config –global user.email “[email protected]”
四、Pull以及Push 使用
至此,git和github的設置就完成了,下面就是如何將本地代碼push到github上,以及如何從github上pull代碼了。
push代碼如下
在github中創建Repository:
https://github.com/ --> New Repository 輸入Repository信息 projectName
在本地創建代碼庫:
創建一個文件夾作爲local repository
$mkdir test
創建一個文件
$cd test
$vi test.txt
將文件添加至local repository
$git add test.txt
初始化local repository
$git init
commit文件
$git commit -a
定義遠程服務器別名
$git remote add alias git@github.com:xxxxx/projectName.git
將本地數據push到github上
$git push alias master
這樣就可以將本地的代碼push到github的repository中了
從github中pull代碼:
在github中搜到你想要pull的代碼,如https://github.com/edgecase/ruby_koans
選擇fork,將此repository fock到你的repository下
在本地創建local repository並初始化
使用命令:
$git pull git@github.com:xxxxx/ruby_koans.git
將github上的代碼pull到local repository中