Git创建分支

1. 从本地分支创建新分支

(Purpose: Whenever you need to create a new feature, fix a bug, or rewrite any of your code, it's a good idea to create a new branch so that none of your changes affect the "master" version of the code.)

当开发一个功能时间较长时,可以创建一个新分支,在新分支上操作避免影响到 master 分支的代码。最终开发完成再合并到 master 分支提交。

# 从master分支拉出一条新的分支,两种方式
# 1. 创建后跳转到新分支
git checkout -b <branch-name>
# 2. 创建后留在master分支
git branch <branch-name>

# 从指定分支拉出一条新的分支
git checkout -b <new-branch> <dev-branch>

2. 从远程仓库里拉取一条新分支

git checkout -b <local-branch-name> <origin/remote-branch-name>

3. 从提交历史(commit)中拉出一条分支

hash 值是指 commit 字段的值。

# 两种方式(一个创建后留在master分支,一个创建后自动切到新分支):
git branch <branch-name> <hash>
git checkout -b <branch-name> <hash> 

例子:

$ git branch
* master
$ git branch commit-branch 735c5b4
$ git branch
  commit-branch
* master

4. 从标签(Tag) 中拉出一条新分支

# 两种方式(一个创建后留在master分支,一个创建后自动切到新分支):
git branch <branch-name> <tag> 
git checkout -b <branch-name> <tag>

例子:

$ git branch tag-branch v0.4.12
$ git branch
  tag-branch
* master

Reference

https://stackabuse.com/git-create-a-new-branch/ 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值