Git 和Github初次使用

转载请注出处 http://hi.baidu.com/kissdev/blog/item/944aa2fab2817215a8d311f1.html

1. GIT

相比CVS/SVN,Git 的优势:
- 支持离线开发,离线Repository
- 强大的分支功能,适合多个独立开发者协作
- 速度块

更多的细节参见 http://mgcore.com/viewthread.php?tid=15556
Git使用指南 http://www.linuxgem.org/user_files/linuxgem/Image/git-tutor.pdf

2. GitHub

GitHub是一个托管Git (开源或闭源)项目的网站,闭源收费,最低7$/月起,免费的300G空间。价格表如下:

使用GitHub步骤:
1、申请GitHub帐户 xxx ,创建名为new-project的新Repository

2、安装Git客户端(Linux)
#yum install git git-gui

3、 生成密钥对,这样项目可以push到 GitHub上
#ssh-keygen -t rsa -C "xxx@gmail.com"

4、将.ssh/id_rsa.pub拷贝到GitHub网站



5、为了方便,设置ssh不输入口令
# eval `ssh-agent`
# ssh-add
(输入passphrase)

6、测试是否能联通GitHub
#ssh git@github.com
如果配置正确,显示
ERROR: Hi xxx! You've successfully authenticated, but GitHub does not provide shell access
Connection to github.com closed.

7、设置Git全局用户配置
# git config --global user.name "xxx"
# git config --global user.email xxx@gmail.com

8、创建本地新项目工作树
# mkdir new-project
# cd new-project
# git init
# touch README
# git add README
# git commit -m 'first commit'
定义远程服务器别名origin
#  git remote add origin git@github.com:xxx/new-project.git  
本地和远程合并,本地默认分支为master
# git push origin master

GitHub网站上就可以看见了, http://github.com/xxx/new-project

9. 更新文件
# vi README
自动commit更改文件
# git commit -a    
更新至远程
# git push origin master

10. 创建和合并分支
#git branch 显示当前分支是master
#git branch new-feature  创建分支
# git checkout new-feature 切换到新分支
# vi page_cache.inc.php
# git add page_cache.inc.php
Commit 到本地GIT
# git commit -a -m "added initial version of page cache"
合并到远程服务器
# git push origin new-feature

如果new-feature分支成熟了,觉得有必要合并进master
#git checkout master
#git merge new-feature
#git branch
#git push
则master中也合并了new-feature 的代码

再登录到GitHub可以看见"Switch Branches"下的分支选项:


GitHub还有一个很实用的功能,查看开发进程网络图(Network):


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值