[TOC]
1.配置全局参数
显示配置信息
> git config --list --global
user.email=summit**@gmail.com
user.name=summit
> git config --global core.eol lf
> git config --global core.autocrlf input
常用git命令
1.添加到缓存区
$ git add .
2.提交到本地
$ git commit -m "bb"
3.上传远程仓库
$ git push origin feature/test1
4.查看分支
$ git branch -a
5.切换分支
$ git checkout <branchName>
6.与远程分支建立连接
$ git branch --set-upstream-to=origin/develop develop
7.拉取代码
$ git pull
8.创建分支
$ git branch f/t2
9.合并其他分支代码
合并f/t1分支代码到f/t2
$ git checkout f/t2
$ git merge f/t1
2.初始化一个新的git仓库并上传到远程仓库
1.创建本地git仓库
>git init
>git add .
>git commit -m "first commit"
2.push到远程仓库
>git push -u origin master
>git remote add origin git@github.com:***/gittest1.git
(使用ssh(当时你可以使用ssh协议) git地址,这边上传github仓库,需要提前在github创建好仓库)
if error fatal: remote origin already exists.
>git remote rm origin
3.上传远程仓库
>git push -u origin master
remote: Permission to ...
fatal: unable to access '***': The requested URL returned error: 403
4.生成公钥
>ssh-keygen -t rsa -C "*****@gmail.com"
如果无权限,我这边ssh验证登陆
github上添加SSH keys
5.看到下面即上传成功
The authenticity of host 'github.com (192.30.255.112)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,192.30.255.112' (RSA) to the list of known hosts.
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 206 bytes | 206.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To github.com:***/gittest1.git
* [new branch] master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
3.git flow工作流程
在git flow之前,需要手动操作分支流程,git flow将操作流程简化成命令,并没有增加新的功能,只是简化了工作
1)初始化
$ git flow init
Which branch should be used for bringing forth production releases?
- master
Branch name for production releases: [master] master
Branch name for "next release" development: [develop] develop
How to name your supporting branch prefixes?
Feature branches? [feature/] feature/
Bugfix branches? [bugfix/] bugfix/
Release branches? [release/] release/
Hotfix branches? [hotfix/] hotfix/
Support branches? [support/] support/
Version tag prefix? []
Hooks and filters directory? [H:/mygittest/.git/hooks]
$ git branch -a
* develop
master
remotes/origin/master
然后就ok
2)分支管理
a.master分支
主分支,上线分支,保护性分支
b.develop分支
开发的基础分支,
c.feature分支
开始feature分支
当需要开发一个新功能,取去创建一个feature/branchName,该分支默认从dev分支检出,
语法:git flow feature start <branchName>
$ git flow feature start test
Switched to a new branch 'feature/test'
Summary of actions:
- A new branch 'feature/test' was created, based on 'develop'
- You are now on branch 'feature/test'
Now, start committing on your feature. When done, use:
git flow feature finish test
完成feature分支
$ git flow feature finish <branchName>
完成一个feature分支
将当前branchName分支代码合并到develop,并删除本地及远程分支
d.release分支
待项目临近发布日期,feature上的分支代码均合并值develop,可以新建一个release分支,
分支命名一般使用版本号V0.0.1
$ git flow release start v0.0.1
Switched to a new branch 'release/v0.0.1'
完成release分支
$ git flow release finish v0.0.1
git-flow 会拉取远程仓库,以确保目前是最新的版本。
release 的内容会被合并到 “master” 和 “develop” 两个分支中去,这样不仅产品代码为最新的版本,而且新的功能分支也将基于最新代码。
为便于识别和做历史参考,release 提交会被标记上这个 release 的名字(在我们的例子里是 “v0.0.1”)。
清理操作,版本分支会被删除,并且回到 “develop”。
e.hotfix分支
用于紧急问题修复
$ git flow hotfix start h0.0.1
完成hotfix分支
$ git flow hotfix finish h0.0.1
完成的改动会被合并到 “master” 中,同样也会合并到 “develop” 分支中,这样就可以确保这个错误不会再次出现在下一个 release 中
4.打tags
1.打标签
git tag -a V0.1.1 -m "Release version V0.1.1"
2.提交远程仓库
git push origin --tags
3.查看所有标签
git tag --list
然后到github查看Tags标签
4.删除本地tags
git tag -d V0.1.1
5.删除远程tags
git push origin :refs/tags/V0.1.1