github常用指令

jopen 11年前發布 | 30K 次閱讀 Git 版本控制系統

總結一下ubuntu下github常用的命令,設置部分跳過,假設repository的名字叫hello-world:

1.創建一個新的repository:

先在github上創建并寫好相關名字,描述。

$cd ~/hello-world        //到hello-world目錄

$git init                     //初始化

$git add .                   //把所有文件加入到索引(不想把所有文件加入,可以用gitignore或add 具體文件)

$git commit               //提交到本地倉庫,然后會填寫更新日志( -m “更新日志”也可)

$git remote add origin git@github.com:WadeLeng/hello-world.git        //增加到remote

$git push origin master    //push到github上

2.更新項目(新加了文件):

$cd ~/hello-world

$git add .                  //這樣可以自動判斷新加了哪些文件,或者手動加入文件名字

$git commit              //提交到本地倉庫

$git push origin master    //不是新創建的,不用再add 到remote上了

3.更新項目(沒新加文件,只有刪除或者修改文件):

$cd ~/hello-world

$git commit -a          //記錄刪除或修改了哪些文件

$git push origin master  //提交到github

4.忽略一些文件,比如*.o等:

$cd ~/hello-world

$vim .gitignore     //把文件類型加入到.gitignore中,保存

然后就可以git add . 能自動過濾這種文件

5.clone代碼到本地:

$git clone git@github.com:WadeLeng/hello-world.git

假如本地已經存在了代碼,而倉庫里有更新,把更改的合并到本地的項目:

$git fetch origin    //獲取遠程更新

$git merge origin/master //把更新的內容合并到本地分支

6.撤銷

$git reset

7.刪除

$git rm  * // 不是用rm

//------------------------------常見錯誤-----------------------------------

1.$ git remote add origin git@github.com:WadeLeng/hello-world.git

 錯誤提示:fatal: remote origin already exists.

 解決辦法:$ git remote rm origin

 然后在執行:$ git remote add origin git@github.com:WadeLeng/hello-world.git 就不會報錯誤了

 2. $ git push origin master

 錯誤提示:error:failed to push som refs to

 解決辦法:$ git pull origin master //先把遠程服務器github上面的文件拉先來,再push 上去。

//------------------------------------------------------------------------------

一個中文git手冊:http://progit.org/book/zh/

</div> 來自:http://hi.baidu.com/wade_hit/item/848869db05e53af4cb0c391b

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!