關於初學者上傳文件到github的方法

轉自http://blog.csdn.net/steven6977/article/details/10567719


【第一步】建立先倉庫

  第一步的話看一般的提示就知道了,在github新建一個repository(谷歌可以解決),都是可視化的界面操作,所以難度不大。或者看這裏:https://help.github.com/articles/create-a-repo 這是官方help,雖然是英文的,但是基本都是圖和代碼,所以很容易讀懂。

  在github首頁的右上角,點擊紅框中的Create New Repo。

  

  

  進入新建倉庫的界面

  

  

  填一下倉庫名稱,Initialize this repository with a README是可選的,不過本人建議最好選上,可以在後面省一個步驟。填好之後,點Create repository就行了。

  【第二步】克隆倉庫

  第二步開始就基本進入命令行模式了,不過要先從github上下載命令行工具。下載地址:http://windows.github.com/ 

  然後進行簡單的安裝之後,會在桌面上創建兩個圖標,GitHub和Git Shell,GitHub是圖形界面,Git Shell是命令行模式,而且默認的Git倉庫是建在C盤的,個人建議要把路徑重設下。

  點開Git Shell,進入命令行。首先我們先要把GitHub上的我們新建的倉庫clone下來,爲了演示,我在GitHub上新建了一個名稱爲myRepoForBlog的git。

  在初始化版本庫之前,先要確認認證的公鑰是否正確,如下:

  ssh -T [email protected]

  正確地結果如下: 

  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,不用理會。

  接下對庫進行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文件夾,進入文件夾目錄,對倉庫進行初始化,如果我們之前沒有勾選創建README,則要先創建README.md文件,不然上傳文件會報錯。如果在第一步就勾選過了,則可以直接進入第四步

  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文件

  創建完README.md後,就可以push了,代碼類似。

  git add .
  git commit -m 'first_commit'
  git remote add origin https://github.com/findingsea/myRepoForBlog.git
  git push origin master

  如果執行git remote add origin https://github.com/findingsea/myRepoForBlog.git,出現錯誤:

  fatal: remote origin already exists

  則執行以下語句:

  git remote rm origin

  再往後執行git remote add origin https://github.com/findingsea/myRepoForBlog.git 即可。

  在執行git push origin master時,報錯:

  error:failed to push som refs to.......

 

  則執行以下語句:

  git pull origin master

  先把遠程服務器github上面的文件拉先來,再push 上去。

  

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