mac os x10.8下如何使用git與github

一、準備工做:git

       下載安裝git客戶端 http://code.google.com/p/git-osx-installer/downloads/list?can=3(安裝了git客戶端,命令行中才有git命令)github

註冊github帳號 https://github.com/ -->Pricing and Signup -->Create a free account
shell

二、建立ssh:(建立ssh目的是將mac與github服務器創建互信)服務器

在local打開terminal:dom

$cd ~/.ssh  檢查是否已經存在ssh(.ssh只是一個demo,它指的是mac存放公鑰的位置,若是第一次ssh鏈接,可跳過此步驟ssh

       若是存在,先將已有的ssh備份,或者將新建的ssh生成到另外的目錄下ide

       若是不存在,經過默認的參數直接生成ssh測試

生成過程以下:google

$ssh-keygen -t rsa -C xxxxx@gmail.com(xxxxx@gmail.com指的是在github註冊的emailspa

Generating public/private rsa key pair.

Enter file in which to save the key (/Users/twer/.ssh/id_rsa): (此處能夠走默認,即公鑰存放在/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 xxxxx@gmail.com

        The key's randomart image is:

        +--[ RSA 2048]----+

        |.o.++===         |

        |.ooo.+. .       |

        |  ..* = E .      |

        |   o = + o       |

        |      . S o      |

        |           .     |

        |                 |

        |                 |

        |                 |

       +-----------------+

此處完成後表示在mac上已經成功生成了與github互信的公鑰

在github中添加ssh:

       登錄github,選擇Account Settings-->SSH  Keys 添加ssh

       Title:xxxxx@gmail.com(title儘可能使用本身的郵箱,這個title與登陸github帳戶的郵箱是不一樣概念,能夠不相同)

Key:打開你生成的id_rsa.pub文件,將其中內容拷貝至此(使用cd命令進入id_rsa.pub目錄,再使用more id_rsa.pub命令查看公鑰的內容)

測試SSH:

$ssh git@github.com

        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(此處表示第一次沒鏈接成功,yes表明再鏈接一次

Warning: Permanently added 'github.com,207.97.227.239' (RSA) to the list of known hosts.

        PTY allocation request failed on channel 0
(在上面那句話執行完以後可能會讓輸入用戶名和密碼,輸入在github註冊的用戶名和密碼便可,認證經過後會在本地存儲一個憑據,之後用戶名和密碼就不須要再輸入了)

Hi xianfuying! You've successfully authenticated, but GitHub does not provide shell access.

                Connection to github.com closed.(若是出現Hi xxx,證實mac與github成功創建了互信)

設置本地git我的信息:(向github提交數據時會顯示下面設置的值,以方便查找誰對這個倉庫作了什麼事)

        $git config --global user.name "your real name"

        $git config --global user.email "xxxxx@gmail.com"

至此,git和github的設置就完成了
三、提交代碼
$git add *
$git commit -m "your commit's reason"(提交代碼到本地倉庫)
$git remote add alias git@github.com:xxxxx/projectName.git( 定義遠程服務器別名爲alias
$git pull -u alias master(將代碼從github pull到本地倉庫
$git pull -uf alias master(強制將代碼從github pull到本地倉庫
$git push -u alias master(將本地倉庫的代碼push到github倉庫)

$git remote -v(查看遠程服務器別名)

$git remote rm alias(刪除遠程服務器別名

相關文章
相關標籤/搜索