手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

分布式版本控制系统Git

[日期:2014-04-16] 来源:Linux社区  作者:Rango Chen [字体:大 中 小]

4 Github的使用


GitHub是一个托管Git项目的网站,对于闭源项目收费,开源项目则免费。使用Github进行代码发布和托管的步骤如下:

1. 登录Github官网https://github.com/ ,申请Github账户,并创建名为github-test的Repository

 

2. 安装Git客户端(Linux)

#yum install git git-gui

 

3. 生成密钥对,并拷贝到Github网站

#ssh-keygen -t rsa -C “xxx@gmail.com”

xxx@gmail.com为你注册Github时的邮箱账户

 

登录Github点击Edit your profile->SSH keys,添加./.ssh/id_rsa.pub中的内容

 

4. 设置ssh不输入口令

#eval `ssh-agent`

#ssh-add

 

5. 测试是否能连接上GIthub

#ssh git@github.com

PTY allocation request failed on channel 0
Hi rangochan! You've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.

连接成功

 

6. 配置Git全局用户配置

# git config --global user.name xxx

# git config --global user.email xxx@gmail.com

xxx及xxx@gmail.com分别为Github账户名和邮箱

 

7. 创建本地新项目

#mkdir github-test

#cd github-test/

#git init

#touch README

#git add README

#git commit -m 'my first commit'

 

定义远程服务器别名origin

#git remote add origin git@github.com:xxx/github-test.git

 

本地和远程实行合并,本地默认为master

#git push origin master

当通过Github以xxx对github-test作出修改时,由于本地快照与Github远程服务器上的不一致,会引起以下错误:

! [rejected] master -> master (fetch first)
error: failed to push some refs to 'git@github.com:xxx/puppet'
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 integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

解决:

通过pull子命令更新Github项目中作出的更改

#git pull origin master

之后再执行git push origin master

Counting objects: 8, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (7/7), 714 bytes | 0 bytes/s, done.
Total 7 (delta 0), reused 0 (delta 0)

 

登录https://github.com/xxx/github-test ,可查看到github-test项目

 

8. 更新文件

#vim README

just for test

 

自动commit更改文件

#git commit -a

 

更新到远程

#git push origin master

 

9. 创建和合并分支

#git branch

* master

显示当前分支是master


#git branch new-branch

创建分支


# git checkout new-branch

切换到新分支


# vi check.py

创建新文件

 

# git add check.py
# git commit -a -m "added a Python script"

Commit 到本地Git


# git push origin new-feature
合并到远程服务器

 

如果new-branch分支成熟了,则可以合并进master
#git checkout master


#git merge new-branch


#git branch

* master
new-banch

 

#git push
执行合并,master中也合并了new-branch中的更新

登录到GitHub,点击"Switch Branches"可以更改分支来查看不同分支下代码情况。

Git 的详细介绍:请点这里
Git 的下载地址:请点这里

linux
相关资讯       Git 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款