我的博客搭建之git的使用

寫在前面

前天我的github博客搭建好啦,並在本地寫了一篇文章我的獨立博客(第一篇)利用git將其push到github上,那麼,今天就簡單記錄下git的使用。整個過程是在windows下操作的。

git將本地項目push到github

1.Git]下載地址
git官網是需要翻牆才能下載的,裏給出Git-2.9.2-64-bit下載地址(我的是64位系統): Git-2.9.2-64-bit

下載後安裝步驟可以參考這裏:Win7下Git的安裝

安裝成功後文件目錄

2. 創建ssh key–安全傳輸

  • 方法1. 使用git gui 直接生成
  • 打開git gui
    help  – show ssh key
  • *方法2. 使用git bash/git cmd 創建(git bash 爲例 )* >設置git的user.name和user.email
    $ git config --global user.name "wblearn"
    $ git config --global user.email "your email"
    >查看是否已經存在ssh key是否存在
    $ cd ~/.ssh
    ![以上步驟截圖](http://upload-images.jianshu.io/upload_images/2556999-463b8867c3907ef7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
    **如果沒有則提示: No such file or directory 
    如果有則進入~.ssh路徑下(ls查看當前路徑文件,rm * 刪除所有文件)生成新的ssh key**
    >生成ssh key
    cd ~ //保持在"~"目錄下
    $ ssh-keygen -t rsa -C "[email protected]"//填寫真實的郵箱
    Generating public/private rsa key pair.
    Enter file in which to save the key (/c/Users/xxxx/.ssh/id_rsa): #不填直接回車
    Enter passphrase (empty for no passphrase): #輸入密碼(可以爲空)
    Enter same passphrase again: #再次確認密碼(可以爲空)
    Your identification has been saved in /c/Users/xxxx/.ssh/id_rsa. #生成的密鑰
    Your public key has been saved in /c/Users/xxxx/.ssh/id_rsa.pub. #生成的公鑰
    ![以上步驟截圖](http://upload-images.jianshu.io/upload_images/2556999-63e1cdae6971a986.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) >添加ssh key到github
    1.打開github→Settings→SSH kyes→Add SSH key
    2.進入c:/Users/xxxx/.ssh/目錄下,打開id_rsa.pub文件,全選複製公鑰內容 
    3.Title自定義,將公鑰粘貼到GitHub中Add an SSH key的key輸入框,最後”Add Key”
    

    測試ssh key是否設置成功

    $ ssh -T [email protected]
    The authenticity of host 'github.com (192.30.253.113)' can't be established.
    RSA key fingerprint is 16:27:xx:xx:xx:xx:xx:4d:eb:df:a6:48.
    Are you sure you want to continue connecting (yes/no)? yes #確認你是否繼續聯繫,輸入yes
    Warning: Permanently added 'github.com,192.30.253.113' (RSA) to the list of known hosts.
    Enter passphrase for key '/c/Users/xxxx/.ssh/id_rsa':  #生成ssh kye是密碼爲空則無此項,若設置有密碼則有此項且,輸入生成ssh key時設置的密碼即可。
    Hi xxx! You've successfully authenticated, but GitHub does not provide shell access. #出現詞句話,說明設置成功。
    

    以上步驟截圖

    3.將本地項目push到github(git cmd爲例)

    打開git cmd 將路徑設置到項目路徑

    Paste_Image.png

    初始化項目

    git init
    >添加遠程倉庫
    git remote add origin "你自己倉庫的地址"
    >push本地項目到遠程倉庫
    git add . //添加所有本地代碼到緩衝區
    git commit -m "first commit"//描述信息
    git push -u origin master//origin也可以自己命名遠程倉庫名稱
    

    ps:我試了兩次沒有push成功,可能是網速的原因,第三次push成功,大家要有耐心哦

    在github查看自己的項目是否傳上去 

    效果圖

  • 寫在最後

    撐着年末,就這樣把自己的獨立博客搭建好了,還有一個星期就2017了,希望2017自己能不斷學習,不斷進步,遇見未來更好的自己。

    我的獨立博客因爲剛剛上線,可能會存在一些問題,歡迎大家幫忙測試,當然你也可以fork,star我的模板。

    發表評論
    所有評論
    還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
    相關文章