GitHub 操做流程示例

最新文章Virson's Bloghtml

參考文章: 博客園-Web前端開發博客園-喻頭快跑GotGitHub前端

 

首先。經過github網站新建一個倉庫,獲得倉庫地址git

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

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

//在客戶端配置帳戶信息
git config --global user.name 'mawanglin2008' //設置初始帳號id
git config --global user.email 'test@test.com' //設置郵箱
//在本地創建本身的版本倉庫
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線上創建倉庫和線下倉庫關聯。shell

新建遠程分支,分帳號先登陸git config設置完畢,去github頁面上找到源目錄,fork先。ssh

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

當出現如下錯誤時:ui

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

解決辦法:spa

ls -al ~/.ssh //check for SSH keys
ssh-keygen -t rsa -C "test@test.com" //generate a new SSH keys
//enter後,輸入兩次passphrase,以後生成了SSH key
pbcopy < ~/.ssh/id_rsa.pub //拷貝公有祕鑰,到github上"add SSH key"
ssh -T git@github.com //輸入passphrase後鏈接成功!

 

其餘參考手冊:code

《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/

相關文章
相關標籤/搜索