Git 基础命令之分支

1、查看分支:

git branch
admin@jimmy MINGW64 /e/Desktop/dbhost (master)
$ git branch
* master

2、创建分支:

git branch devlopment
admin@jimmy MINGW64 /e/Desktop/dbhost (master)
$ git branch devlopment

admin@jimmy MINGW64 /e/Desktop/dbhost (master)
$ git branch
  devlopment
* master


3、切换分支:

git checkout {分支名}
admin@jimmy MINGW64 /e/Desktop/dbhost (master)
$ git checkout devlopment
Switched to branch 'devlopment'

新建分支修改不影响主干:

admin@jimmy MINGW64 /e/Desktop/dbhost (devlopment)
$ git status
On branch devlopment
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   readme.txt

no changes added to commit (use "git add" and/or "git commit -a")

admin@jimmy MINGW64 /e/Desktop/dbhost (devlopment)
$ git add .

admin@jimmy MINGW64 /e/Desktop/dbhost (devlopment)
$ git commit -m 分支开发
[devlopment 8650f07] 分支开发
 1 file changed, 1 insertion(+), 1 deletion(-)


4、将分支合并为主干:

(1)先切换回主干:

git checkout master
admin@jimmy MINGW64 /e/Desktop/dbhost (devlopment)
$ git checkout master
Switched to branch 'master'


(2)合并分支:

git merge {分支名}
admin@jimmy MINGW64 /e/Desktop/dbhost (master)
$ git merge devlopment
Updating dbaffde..8650f07
Fast-forward
 readme.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


(3)(谨慎使用删除) 合并后,删除分支:

git branch -d {分支名}
admin@jimmy MINGW64 /e/Desktop/dbhost (master)
$ git branch -d devlopment
Deleted branch devlopment (was 8650f07).

admin@jimmy MINGW64 /e/Desktop/dbhost (master)
$ git branch
* master


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值