第一步:
下載安裝git客戶端 http://code.google.com/p/git-osx-installer/downloads/list?can=3
註冊github賬號 https://github.com/ -->Pricing and Signup -->Create a free account
申請gitHub用戶名密碼:
zhch1991
8256076chu(小寫)
第二步:
創建ssh:
在local打開terminal:
$cd ~/.ssh 檢查是否已經存在ssh
如果存在,先將已有的ssh備份,或者將新建的ssh生成到另外的目錄下
如果不存在,通過默認的參數直接生成ssh
生成過程如下:
$ssh-keygen -t rsa -C [email protected](註冊github時的email)
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/twer/.ssh/id_rsa):
Created directory '/Users/twer/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/twer/.ssh/id_rsa.
Your public key has been saved in /Users/twer/.ssh/id_rsa.pub.
The key fingerprint is:
18:16:11:c9:01:6c:48:09:7f:27:c6:43:0d:7f:3f:84 [email protected]
The key's randomart image is:
+--[ RSA 2048]----+
|.o.++=== |
|.ooo.+. . |
| ..* = E . |
| o = + o |
| . S o |
| . |
| |
| |
| |
+-----------------+
如果要修改ssh生成目錄,在藍色位置處輸入要生成的路徑,選擇默認的話,會生成在 ~/.ssh下
第三步:
在github中添加ssh:
登陸github,選擇Account Settings-->SSH Public Keys 添加ssh
Title:[email protected]
Key:打開你生成的id_rsa.pub文件,將其中內容拷貝至此
測試SSH:
$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
Warning: Permanently added 'github.com,207.97.227.239' (RSA) to the list of known hosts.
PTY allocation request failed on channel 0
Hi xianfuying! You've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.
在藍色位置處輸入 yes
第四步:
$git config --global user.name "your real name"
$git config --global user.email "[email protected]"
至此,git和github的設置就完成了,下面就是如何將本地代碼push到github上,以及如何從github上pull代碼了:
第五步:
在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 [email protected]:xxxxx/projectName.git
將本地數據push到github上
$git push alias master
這樣就可以將本地的代碼push到github的repository中了
至此,簡單的gitHub倉庫已建立完畢
第八步:
開發人員使用git進行本地開發
將遠程工程拿下來:
git clone https://github.com/zhch1991/happyppy.git