标签:git分支
Windows上git的简单使用
git客户端安装(略)
1)生成ssh密钥:
$ ssh-keygen -t rsa -C "bunny@olymtech.com" Generating public/private rsa key pair. Enter file in which to save the key (/c/Users/bunny/.ssh/id_rsa): Created directory ‘/c/Users/bunny/.ssh‘. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /c/Users/bunny/.ssh/id_rsa. Your public key has been saved in /c/Users/bunny/.ssh/id_rsa.pub. The key fingerprint is: 74:6e:f3:14:0a:95:c3:d8:8e:50:62:b3:b2:79:45:4d bunny@olymtech.com bunny@BUNNY-PC /E/gittest
将生成的公钥文件id_rsa.pub内容拷贝至gitlab管理界面SSH Keys下:
2)从服务端clone一份project来测试
$ git clone git@git.olymtech.com:bunny/com-gittest.git Cloning into ‘com-gittest‘... The authenticity of host ‘git.olymtech.com (183.131.76.44)‘ can‘t be established . RSA key fingerprint is db:af:31:f4:1c:3f:38:39:48:84:24:ac:08:34:ad:bc. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added ‘git.olymtech.com,183.131.76.44‘ (RSA) to the list of known hosts. warning: You appear to have cloned an empty repository. Checking connectivity... done.
$ cd com-gittest/ $ git init Reinitialized existing Git repository in e:/gittest/com-gittest/.git/ bunny@BUNNY-PC /E/gittest/com-gittest (master) $ touch README bunny@BUNNY-PC /E/gittest/com-gittest (master) $ git add README bunny@BUNNY-PC /E/gittest/com-gittest (master) $ git commit -m ‘first commit test‘ [master (root-commit) 9c37bb4] first commit test 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 README bunny@BUNNY-PC /E/gittest/com-gittest (master) $ git remote add origin git@git.olymtech.com:bunny/com-gittest.git fatal: remote origin already exists. bunny@BUNNY-PC /E/gittest/com-gittest (master) $ git push -u origin master Counting objects: 3, done. Writing objects: 100% (3/3), 206 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) To git@git.olymtech.com:bunny/com-gittest.git * [new branch] master -> master Branch master set up to track remote branch master from origin.
图形化界面git分支管理使用方法
使用sourcetree的git客户端(安装略,安装过程忽略安装mercurial客户端),下载地址http://www.sourcetreeapp.com/download/
1. 使用git自带的git branch 分支管理命令:
新建分支并推送:
找一台机器clone下来验证分支OK:
git@pubgit:/tmp$ git clone http://git.olymtech.com/bunny/com-gittest.git
Cloning into ‘com-gittest‘...
Username for ‘http://git.olymtech.com‘: bunny
Password for ‘http://bunny@git.olymtech.com‘:
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
Checking connectivity... done.
git@pubgit:/tmp/com-gittest$ git branch -r
origin/HEAD -> origin/master
origin/b_dev
origin/b_release
origin/master
2. 使用git flow来简化分支管理:
git flow 初始化仓库(使用默认分支流):
找一台客户端机器验证服务端分支:
git@pubgit:/tmp$ git clone http://git.olymtech.com/bunny/com-bunnytest.git
git@pubgit:/tmp/com-bunnytest$ git branch -r
origin/HEAD -> origin/master
origin/develop
origin/master
命令行下git分支的简单使用:
git branch 不带参数:列出本地已经存在的分支
git branch -r 列出远程分支
git branch -a 列出本地分支和远程分支
git branch 创建一个新的本地分支,需要注意,此处只是创建分支,不进行分支切换,例如:
#git branch newbranch2
git checkout newbranch2切换至新创建分支
git checkout master 切换回主分支
git branch -m | -M oldbranch newbranch 重命名分支,如果newbranch名字分支已经存在,则需要使用-M强制重命名,否则,使用-m进行重命名。
git branch -d | -D branchname 删除branchname分支
git branch -d -r branchname 删除远程branchname分支
补充说明:
git flow定义了下列分支
主要分支
1. master: 永远在 production-ready 状态
2.develop: 最新的下次发布开发状态j
支援性分支
1. Feature branches: 开发新功能都从 develop 分支出來,完成后 merge 回 develop
2. Release branches: 准备要 release 的版本,只修 bugs。从 develop 分支出來,完成后 merge 回 master 和 develop
3. Hotfix branches: 等不及 release 版本就必须马上修 master 上线的情況。会从 master 分支出來,完成后 merge 回 master 和 develop
http://blog.csdn.net/menxu_work/article/details/12494903
git如果需进行分支管理,两种方式:
1. 本地建立分支提交至服务端,如果不行排查下权限或使用上的问题。
Git Bash+EGit在项目中配合使用最常用方法总结,可参考此博文写的很详细
http://blog.csdn.net/hongshan50/article/details/22582049
2. 使用git flow(约定俗成的开发规范), SourceTree工具: 既有GitBash的命令行,又有EGit的图形化管理 有个git flow选项功能
本文出自 “E人空间” 博客,请务必保留此出处http://iceeggplant.blog.51cto.com/1446843/1611148
标签:git分支
原文地址:http://iceeggplant.blog.51cto.com/1446843/1611148