git branch 查看分支:
git branch 创建分支:
git checkout 或者git switch 切换分支:
git checkout -b 或者git switch -c 创建+切换分支:
git merge 合并某分支到当前分支:
git branch -d 删除分支:
[root@localhost ~]# ll
总用量 44
drwxr-xr-x. 3 root root 29 11月 12 16:52 222
drwxrwxr-x. 29 root root 24576 11月 11 16:32 git-2.29.2
drwxr-xr-x. 3 root root 35 11月 13 11:58 gitskill
-rw-r--r--. 1 root root 25 11月 7 22:18 wang.sh
[root@localhost ~]# git branch
[root@localhost ~]# cd 222
[root@localhost 222]# git branch
* master
[root@localhost 222]# git checkout -b dev
切换到一个新分支 'dev'
[root@localhost 222]# git checkout master
切换到分支 'master'
您的分支与上游分支 'origin/master' 一致。
[root@localhost 222]# git switch dev
切换到分支 'dev'
[root@localhost 222]# git switch -c deve
切换到一个新分支 'deve'
[root@localhost 222]# ll
总用量 4
-rw-r--r--. 1 root root 4 11月 12 16:52 aaa
[root@localhost 222]# vim aaa
[root@localhost 222]# vim aaa
[root@localhost 222]# git add aaa
[root@localhost 222]# git commit -m sss
[deve 5b565cd] sss
1 file changed, 1 insertion(+)
[root@localhost 222]# git switch master
切换到分支 'master'
您的分支与上游分支 'origin/master' 一致。
[root@localhost 222]# git merge deve
更新 2b00888..5b565cd
Fast-forward
aaa | 1 +
1 file changed, 1 insertion(+)
[root@localhost 222]# cat aaa
bbb
sss
[root@localhost 222]# git branch -d deve
已删除分支 deve(曾为 5b565cd)。
[root@localhost 222]# git branch -d dev
已删除分支 dev(曾为 2b00888)。
[root@localhost 222]# git branch
* master
[root@localhost 222]#
master分支是一条线,Git用master指向最新的提交,再用HEAD指向master
当我们创建新的分支,例如dev时,Git新建了一个指针叫dev,指向master相同的提交,再把HEAD指向dev,就表示当前分支在dev上: