如下介紹GITHUB的一些基本操做和命令;沒有什麼理論,以實踐爲主git
準備工做github
①:在www.github.com網站註冊本身的賬號shell
②:在本地的機子上安排GIT HUB的客戶端bash
GITHUB使用的情景一:服務器
在github網站上建立一個git倉庫,Copy到本地ide
①:登陸到GITHUB工具
②:在[Repositories]頁籤中,找到New按鈕,建立一個GIT倉庫,假定名稱爲"HelloGIT"fetch
輸入描述信息,點擊"Create repository"完成在WebSite中建立Git倉庫網站
建立HelloGit完成後,能夠看到它其實是執行了如下命令:rem
touch README.md git init git add README.md git commit -m "first commit" git remote add origin https://github.com/zyguo1006/HelloGit.git git push -u origin master
以上,是建立GIT倉庫的代碼,咱們在Git Shell中也能夠直接用這些命令,建立一個Repository並Push到GitHub Website.如下是這些命令的說明:
1:建立一個readme的文件,
2:初始化github repository,
3:使readme.md文件處於Stage狀態, (若是修改了文件,也須要使用git add "xxx.txt"提交這些變動)
4:提交上面的修改,並添加信息.
5:建立一個origin在git上,
6:建立主分支.
操做場景二: 把這個新建立的倉庫Clone到本地,並在本地建立一個文件,提交到Git Hub
打開Git Shell窗口,找到要放置Git倉庫的文件夾,我假設放在E盤:先進入到E盤.
git clone https://github.com/zyguo1006/HelloGit.git
把GitHub中的倉庫Copy到了E盤. 而後,在HelloGit文件夾下建立一個readme.txt文件,並寫入一些內容.如今要把readme.txt文件提交到GitHub服務器的HelloGit倉庫中.則執行如下操做便可:
cd E: ./HelloGit git add "readme.txt" git commit -m "add readme file by git shell" git push
操做場景三: 對同一文件進行修改,衝突的解決
①:先在WebSite中修改readme.txt文件夾的內容,並提交.
②:而後在本地修改readme.txt的內容,
執行如下操做:
git add "readme.txt" git commit -m "update readme file at local then submit" git push
以上,是把修改的readme.txt的內容提交到GitHUB master.可是因爲原來這個文件已經有修改,故衝突,產生了如下問題:
! [rejected] master -> master (fetch first) error: failed to push some refs to 'https://github.com/zyguo1006/HelloGit.git' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first merge the remote changes (e.g., hint: 'git pull') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
如何解決衝突呢?
第一種方法是強制覆蓋:
git push -f
這樣,就會把原來的修改給覆蓋掉,只剩下Client提交的修改
第二種方法是先取得已經提交的修改,比較衝突,修改完成後,再提交:
git pull
這樣,readme.txt文件出現如下狀況:
HelloGIT at client <<<<<<< HEAD Update readme file at local and submit to test reslove the confict. hubert ======= Update readme file at local and submit to test reslove the confict testsdfsdfsdfsdfsdfsd >>>>>>> 239b3c2cedd978fdd9f567ce6920fc17e7110daa
其中 <<<<<<< Head和========之間的部分是本次要提交的
=======和>>>>>>>是服務器上如今的,
把這些符號去掉後,就執行
git add "readme.txt" git commit -m "meger readme" git push
就能夠提交成功.
第三種是在第二種的基礎上用代碼比較工具,完成比較和合並和再提交.