需要熟記的git命令

需要熟記的github常用命令

總結一下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 [email protected]: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 [email protected]:WadeLeng/hello-world.git

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

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

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

6.撤銷

$git reset

7.刪除

$git rm * // 不是用rm

//——————————常見錯誤———————————–

1.$ git remote add origin [email protected]:WadeLeng/hello-world.git

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

解決辦法:$ git remote rm origin

然後在執行:$ git remote add origin [email protected]: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/


reference:http://blog.csdn.net/lujinjian605894472/article/details/8443485

發佈了104 篇原創文章 · 獲贊 9 · 訪問量 37萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章