To git@github.com:mintist/JFF-RTOS.git ! [rejected] master -> master (non-fast-forward)error: failed to push some refs to 'git@github.com:mintist/JFF-RTOS.git'To prevent you from losing history, non-fast-forward updates were rejectedMerge the remote changes (e.g. 'git pull') before pushing again. See the'Note about fast-forwards' section of 'git push --help' for details.
如果遇到錯誤,再拉一下就好了~~
還有平常的一些更新啥的請看下文,親測可用~~~
總結一下ubuntu下github常用的命令,設定部分跳過,假設repository的名字叫hello-world:
1.建立一個新的repository:
先在github上建立並寫好相關名字,描述。
$cd ~/hello-world //到hello-world目錄,本地目錄名與repository的名字不一定相同
$git init //初始化
$git add . //把所有檔案加入到索引(不想把所有檔案加入,可以用gitignore或add 具體檔案,見下文)
$git commit //提交到本地倉庫,然後會填寫更新日誌( -m “更新日誌”也可,如$git commit -m “my first vesion of ...”)
$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 //提交到本地倉庫,不加參數會提示,注意:^=Ctrl,按照提示來就好了~~~
$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/
http://hi.baidu.com/wade_hit/item/848869db05e53af4cb0c391b