天天看點

GitHub 操作流程示例

最新文章:Virson's Blog

參考文章: 部落格園-Web前端開發,部落格園-喻頭快跑,GotGitHub

首先。通過github網站建立一個倉庫,得到倉庫位址

https://github.com/mawanglin2008/test.git      

接着回到用戶端,打開git shell:

//在用戶端配置賬戶資訊
git config --global user.name 'mawanglin2008' //設定初始賬号id
git config --global user.email '[email protected]' //設定郵箱
//在本地建立自己的版本倉庫
cd d: //我把版本倉庫建立在D盤,切換到D盤目錄
mkdir a //建立檔案夾,注意本地倉庫名要和git上建立的倉庫名一緻
cd a //進入a目錄
git init //初始化版本倉庫
touch README //建立一個README檔案,之後編輯README
git add README //将檔案添加到上傳隊列
git commit -m 'information' //送出
git remote add origin https://github.com/mawanglin2008/test.git //遠端位址
//如果這裡有錯,錯誤資訊為fatal: remote origin already exists時,請輸入:git remote rm origin,然後繼續輸入上面那行繼續走流程。
git push origin master //上傳到遠端版本庫。輸入github郵箱和密碼      

ok,已經完成github線上建立倉庫和線下倉庫關聯。

建立遠端分支,分賬号先登入git config設定完畢,去github頁面上找到源目錄,fork先。

git clone https://github.com/mawanglin2008/test.git //克隆,并在本地目錄自動建立本地倉庫
cd a
git checkout -b dev //建立并切換到dev分支
git push --set-upstream origin dev //向主分支送出建立分支資訊
//輸入主分支郵箱和密碼,通過。遠端分支建立完畢
//編輯内容
git add .
git commit -m 'add dev' //彙總目錄
git push //送出      

遠端分支工作完畢,回到master工作環境:

git checkout master
git merge dev --no-ff //merge合并工作先
git pull origin dev //從dev分支拉回較新代碼
git push //更新至master賬号下面,共其他分支pull      

當出現以下錯誤時:

Permission denied (publickey).
fatal: Could not read from remote repository.
 
Please make sure you have the correct access rights
and the repository exists.      

解決辦法:

ls -al ~/.ssh //check for SSH keys
ssh-keygen -t rsa -C "[email protected]" //generate a new SSH keys
//enter後,輸入兩次passphrase,之後生成了SSH key
pbcopy < ~/.ssh/id_rsa.pub //拷貝公有秘鑰,到github上"add SSH key"
ssh -T [email protected] //輸入passphrase後連接配接成功!      

其他參考手冊:

《Git Community Book 中文版》:http://gitbook.liuhui998.com/

《GIT GUI使用》:http://hi.baidu.com/lettoo/blog/item/e2e7f30fec72bdf6ab645789.html

《Generating SSH keysGenerating SSH keys》:https://help.github.com/articles/generating-ssh-keys/