Git使用
来源:互联网 发布:祖玛的复仇2mac版 编辑:程序博客网 时间:2024/04/29 16:24
使用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):
git简明教程
以一个测试用的项目为例(git://github.com/royzhu/test.git)
转到你的工作目录
roy@ubuntu:~/$ cd workspace
创建、下载项目文件夹(不知道是不是该叫它“包”)
roy@ubuntu:~/workspace$ git clone git://github.com/royzhu/test.git
等待一段时间后,项目就下好了
roy@ubuntu:~/workspace$ ls -la
drwxr-xr-x 3 roy roy 4096 2008-04-29 17:10 test
roy@ubuntu:~/workspace$ cd test
查看主枝和分支。登录GitHub.com,加入项目后,在项目里的Network有图形化的分支图
roy@ubuntu:~/workspace/test$ git show-branch
[master] a new branch
master是默认的住分支名
为远程版本库起别名:(一般默认为origin)好处是省得输入那么长的版本库名称
roy@ubuntu:~/workspace/test$ git remote add origin git@github.com:royzhu/test.git
建立自己的分支
roy@ubuntu:~/workspace/test$ git branch your_branch_name
再看看有哪些分支
roy@ubuntu:~/workspace/test$ git show-branch
! [your_branch_name] a new branch
--
*+ [master] a new branch
查看现在使用的分支
roy@ubuntu:~/workspace/test$ git branch
* master
your_branch_name
加*号表示当前使用的分支
进入自己的分支
roy@ubuntu:~/workspace/test$ git checkout your_branch_name
再看看
roy@ubuntu:~/workspace/test$ git branch
master
* your_branch_name
添加、修改些东西吧
roy@ubuntu:~/workspace/test$ vim something
把文件加入跟踪(每次提交前必须写这步)
roy@ubuntu:~/workspace/test$ git add something
提交修改(提交到本地,没有传到服务器)
roy@ubuntu:~/workspace/test$ git commit -m '说明'
提交分支到服务器
roy@ubuntu:~/workspace/test$ git push origin your_branch_name
“origin”是固定的
获得最新的项目文件(从服务器下载)
roy@ubuntu:~/workspace/test$ git pull git://github.com/royzhu/test.git
- 【git】VS2015使用Git
- 【GIT】 git rebase 使用
- 【Git】Git客户端使用
- 使用git
- git使用
- Git使用
- Git使用
- git 使用
- Git使用
- git使用
- git使用
- git 使用
- git 使用
- git 使用
- git 使用
- git 使用
- Git使用
- git 使用
- Problem 46
- SQL Server 2008 R2: Enable the remote connection and sa login
- java高级视频-IO输入与输出[学习中……]
- django model API参考
- poj 3233 Matrix Power Series
- Git使用
- How to install DBDesigner 4
- PHP代码:验证IPV6地址是否合法的正则
- Everyone dreams of getting a perfectly slim and trim body
- c# 右下角弹出和关闭窗口
- IPv6的地址格式简介
- c语言链表
- 关于服务器端的业务处理过程中让客户端弹出confirm对话框,并根据confirm,判断继续业务逻辑的处理
- 代序:“淡”是人生最深的滋味----------读后感