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 '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线上建立仓库和线下仓库关联。

新建远程分支,分账号先登录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 "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后连接成功!

 

其他参考手册:

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

posted @ 2015-04-19 13:30  学海无涯1999  阅读(719)  评论(0编辑  收藏  举报