mac os x10.8下如何使用git与github
2019獨角獸企業重金招聘Python工程師標準>>>
1、準備工作:
?????? 下載安裝git客戶端 http://code.google.com/p/git-osx-installer/downloads/list?can=3(安裝了git客戶端,命令行中才有git命令)
注冊github賬號 https://github.com/ -->Pricing and Signup -->Create a free account
2、創建ssh:(創建ssh目的是將mac與github服務器建立互信)
在local打開terminal:
$cd ~/.ssh? 檢查是否已經存在ssh(.ssh只是一個demo,它指的是mac存放公鑰的位置,如果第一次ssh連接,可跳過此步驟)
?????? 如果存在,先將已有的ssh備份,或者將新建的ssh生成到另外的目錄下
?????? 如果不存在,通過默認的參數直接生成ssh
生成過程如下:
$ssh-keygen -t rsa -C xxxxx@gmail.com(xxxxx@gmail.com指的是在github注冊的email)
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的設置就完成了
3、提交代碼
$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(刪除遠程服務器別名)
轉載于:https://my.oschina.net/ghm7753/blog/398244
總結
以上是生活随笔為你收集整理的mac os x10.8下如何使用git与github的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 剖析ASSERT函数
- 下一篇: 梦到死人活过来了是什么意思