之前有寫了兩篇在windows下使用Visual Studio連接GitHub的文章,有需求的可以去看一下。windows中使用Git工具連接GitHub(配置篇) 和 在Visual Studio中使用GitHub(使用篇)
本文是講在Mac OS中使用XCode連接GitHub。
軟件版本:
Mac OS 10.7.4
XCode 4.3.2
不需要另行安裝任何軟件,XCode的默認源碼管理軟件就是Git。所以我們要做的只是配置而已。
紅色為輸入命令 藍色為自行輸入的參數 綠色為注釋 紫色為您系統參數
一、為您的SSH生成密鑰
jomatoMac-mini:~ sorex1984$ ssh-keygen -t rsa -C "your_email@youremail.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/sorex1984/.ssh/id_rsa): abcde[文件名]
Enter passphrase (empty for no passphrase): [密碼必須大於4位]
Enter same passphrase again: [再次輸入密碼]
Your identification has been saved in abcde.
Your public key has been saved in abcde.pub.
The key fingerprint is:
ea:74:df:7d:29:de:c9:37:80:49:be:d9:5c:9e:03:94 your_email@youremail.com
The key's randomart image is:
+--[ RSA 2048]----+
| |
| |
| . |
| . E |
| S o + |
| . + o . |
| o . = = o|
| o . . + =o*+|
| . . o.o=+|
+-----------------+
在/Users/sorex1984/文件夾下我們會看到有abcde和abcde.pub兩個文件
二、在GitHub網站上的SSH Key中加入abcde.pub的內容
這里就不詳細描述了,不知道怎么加的可以去看windows中使用Git工具連接GitHub(配置篇)
三、添加SSH到管理器並測試連接
jomatoMac-mini:~ sorex1984$ ssh-add ~/abcde
jomatoMac-mini:~ sorex1984$ ssh -T git@github.com
The authenticity of host 'github.com (207.97.227.239)' can't be established.RSA key fingerprint is ea:74:df:7d:29:de:c9:37:80:49:be:d9:5c:9e:03:94.Are you sure you want to continue connecting (yes/no)?
jomatoMac-mini:~ sorex1984$ yes
Hi username! You've successfully authenticated, but GitHub does not provide shell access.
四、關聯項目
cd 項目文件夾
git remote add origin git@github.com:sorex/iPhoneStudy.git[項目地址]
git pull -u origin master[從網址拉取項目]
git push -u origin master[向網站提交項目]
五、XCode中提交項目
提交到本地:選擇要 更新的文件 右鍵 –> Source Control –> Commit Selected Files [填寫注釋]
提交到GitHub:File菜單–> Source Control–> Push… –> 選擇Remote[一般選擇origin/master]
從GitHub獲取:File菜單–> Source Control–> Pull… –> 選擇Remote[一般選擇origin/master]
設置個人信息
$ git config --global user.name "sorex"
$ git config --global user.email "sorex1984@gmail.com"
到此全部完畢您可以使用GitHub來同步或者發布您的代碼了。
注:每次重啟MAC OS后都需要重新添加key文件
ssh-add ~/abcde
ssh -T git@github.com