如何創建github遠程倉庫
首先, 你有先到github網站注冊賬號https://github.com
然后創建一個項目, Create a new repository
之后在在Repository name 填入 ZXTabBarController(你的遠程倉庫名) ,其他保持默認設置,
點擊"Create repository"按鈕,就成功地創建了一個新的Git倉庫:
打開終端進入你的文件目錄
ssh-keygen -t rsa -C "zhouxihi@aliyun.com"
改為你在 github 上注冊的郵箱,之后會要求確認路徑和輸入密碼,我們這使用默認的一路回車就行。
成功的話會在~/下生成.ssh文件夾,
進去,打開 id_rsa.pub,復制里面的 key
vi /Users/jackey/.ssh/id_rsa.pub
復制里面的所有內容, 然后回到github網頁選擇setting
進入settings后選擇SSH and GPG keys
選擇New SSH Key
輸入完title和key后選擇Add SSH key按鈕完成添加
現在回到終端, 測試下是否能連接到github服務器
ssh -T git@github.com
看到這樣的提示就說明設置好了
bogon:ZXTabBarController jackey$ ssh -T git@github.com Hi zhouxihi! You've successfully authenticated, but GitHub does not provide shell access.
然后就可以將本地文件push到遠程倉庫了
首先初始化本地倉庫
git init
添加文件
git add .
寫入緩存
git commit -m 'first upload'
添加遠程倉庫
git remote add origin git@github.com:zhouxihi/ZXTabBarController.git
推送文件到遠程倉庫
git push -u origin master
顯示100%. done就可以了
bogon:ZXTabBarController jackey$ git push -u origin master Counting objects: 57, done. Delta compression using up to 4 threads. Compressing objects: 100% (51/51), done. Writing objects: 100% (57/57), 86.20 KiB | 0 bytes/s, done. Total 57 (delta 14), reused 0 (delta 0) remote: Resolving deltas: 100% (14/14), done. To git@github.com:zhouxihi/ZXTabBarController.git * [new branch] master -> master Branch master set up to track remote branch master from origin.
以后每次有修改本地文件就只要下面三個步驟就可以推送到服務器了
->git add.
->git commit -m 'second upload'
->git push -u origin master
如果想從服務器拉下來, 可以用指令
git clone https://github.com/zhouxihi/ZXTabBarController.git