【第一步】建立先倉庫
第一步的話看一般的提示就知道了抒抬,在github新建一個repository(谷歌可以解決),都是可視化的界面操作,所以難度不大秃励。或者看這里:https://help.github.com/articles/create-a-repo?這是官方help吉捶,雖然是英文的夺鲜,但是基本都是圖和代碼皆尔,所以很容易讀懂。
在github首頁的右上角币励,點擊紅框中的Create New Repo慷蠕。
進(jìn)入新建倉庫的界面
填一下倉庫名稱,Initialize this repository with a README是可選的榄审,不過本人建議最好選上砌们,可以在后面省一個步驟。填好之后搁进,點Create repository就行了浪感。
【第二步】克隆倉庫
第二步開始就基本進(jìn)入命令行模式了,不過要先從github上下載命令行工具饼问。下載地址:http://windows.github.com/
然后進(jìn)行簡單的安裝之后影兽,會在桌面上創(chuàng)建兩個圖標(biāo),GitHub和Git Shell莱革,GitHub是圖形界面峻堰,Git Shell是命令行模式,而且默認(rèn)的Git倉庫是建在C盤的盅视,個人建議要把路徑重設(shè)下捐名。
點開Git Shell,進(jìn)入命令行闹击。首先我們先要把GitHub上的我們新建的倉庫clone下來镶蹋,為了演示,我在GitHub上新建了一個名稱為myRepoForBlog的git赏半。
在初始化版本庫之前贺归,先要確認(rèn)認(rèn)證的公鑰是否正確,如下:
ssh -T git@github.com
正確地結(jié)果如下:
Warning: Permanently added 'github.com,207.97.227.239' (RSA) to the list of known hosts.
Hi findingsea! You've successfully authenticated, but GitHub does not provide shell access.
會有一個Warning断箫,不用理會拂酣。
接下對庫進(jìn)行clone,如下:
···
git clone https://github.com/findingsea/myRepoForBlog.git
···
上面的地址可以在如下界面找到:
clone成功如下:
Cloning into 'myRepoForBlog'...
Warning: Permanently added 'github.com,207.97.227.239' (RSA) to the list of known hosts.
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.
【第三步】上傳README.md文件
這個時候仲义,我們的GitHub文件夾下就多了一個myRepoForBlog文件夾婶熬,進(jìn)入文件夾目錄,對倉庫進(jìn)行初始化埃撵,如果我們之前沒有勾選創(chuàng)建README赵颅,則要先創(chuàng)建README.md文件,不然上傳文件會報錯盯另。如果在第一步就勾選過了
性含,則可以直接進(jìn)入第四步。
git init
touch README.md
git add README.md
git commit -m 'first_commit'
git remote add origin https://github.com/findingsea/myRepoForBlog.git
git push origin master
【第四步】push文件
創(chuàng)建完README.md后鸳惯,就可以push了商蕴,代碼類似叠萍。
git add .
git commit -m 'first_commit'
git remote add origin https://github.com/findingsea/myRepoForBlog.git
git push origin master
如果執(zhí)行:git remoteaddoriginhttps://github.com/findingsea/myRepoForBlog.git
出現(xiàn)錯誤:fatal: remote origin already exists
則執(zhí)行以下語句:
git remote rm origin
再往后執(zhí)行:git remote add origin?https://github.com/findingsea/myRepoForBlog.git?即可。
在執(zhí)行g(shù)it push origin master時绪商,報錯:
error:failed to push som refs to.......
則執(zhí)行以下語句:
git pull origin master
先把遠(yuǎn)程服務(wù)器github上面的文件拉先來苛谷,再push 上去。